Run Casdoor with Docker
This guide explains how to run Casdoor in a Docker container and sign in to the admin console.
Learning outcomes
- Choose between the two Casdoor images.
- Start Casdoor with one command for a trial.
- Run Casdoor against your own database with
docker runor Docker Compose.
What you need
- Docker on Linux, Windows, or macOS. On Linux, Docker Engine 17.05 or later.
- At least 100 MB of RAM to run a pre-built image. At least 2 GB of RAM to build the image yourself, because the frontend build fails with less.
- For Docker Compose: Docker Compose v2.2 or later. On Linux, you install Compose separately from Docker Engine.
- For the standard image: a supported database that the container can reach.
Casdoor Cloud gives you a dedicated Casdoor instance that we host and keep upgraded for you, from $9/month with no per-user fees. New accounts get $4 in free credit to try it.
Choose an image
Casdoor publishes two images on Docker Hub:
| Image | Contents | Use it for |
|---|---|---|
casbin/casdoor-all-in-one | Casdoor with an embedded SQLite database and default settings | A quick trial. Not for production |
casbin/casdoor | Casdoor only | Production, connected to your own database |
Try Casdoor with the all-in-one image
-
Start the container. Docker pulls the image if you don't have it.
docker run -p 8000:8000 casbin/casdoor-all-in-one -
Open
http://localhost:8000in a browser. Casdoor opens the Welcome to Casdoor page. -
Set the password of the administrator
adminand click Set Password. See Sign in to the admin console. -
Sign in with the organization
built-in, the usernameadmin, and the password that you set.
The data lives in a SQLite file inside the container and is lost when you remove the container.
Run the standard image with your database
Pass the settings to the container in one of two ways.
Pass settings as environment variables
This is the recommended way. Every option of app.conf is also an environment variable.
-
Start the container with the database settings:
docker run \
-e driverName=mysql \
-e dataSourceName='<user>:<password>@tcp(<host>:3306)/' \
-p 8000:8000 \
casbin/casdoor:latest<user>and<password>: the database account.<host>: the address of the database as seen from inside the container.
To set the password of
built-in/adminwithout the welcome page, also pass-e initAdminPassword=<admin-password>. It applies only when Casdoor creates a new database. -
Open
http://localhost:8000, set the password ofadminon the Welcome to Casdoor page, and sign in asbuilt-in/admin. See Sign in to the admin console.
Mount a configuration file
-
Copy
conf/app.confto a folder on the host and set the database connection. See Configure the database. -
Start the container and mount the folder at
/conf, so that the file is at/conf/app.confinside the container:docker run -p 8000:8000 -v /folder/of/app.conf:/conf casbin/casdoor:latest -
Open
http://localhost:8000, set the password ofadminon the Welcome to Casdoor page, and sign in asbuilt-in/admin. See Sign in to the admin console.
Casdoor runs as uid and gid 1000 inside the container. When you mount a volume that Casdoor writes to, for example for a SQLite file, make the path writable by uid 1000. Otherwise Casdoor fails with permission denied.
Run Casdoor and a database with Docker Compose
The Casdoor repository contains a docker-compose.yml that starts Casdoor together with a MySQL 8.0 database. The db service has a health check that runs mysqladmin ping, and Casdoor starts only after the database reports healthy (depends_on with condition: service_healthy).
-
Clone the repository or copy
docker-compose.ymlto a folder. -
Put
app.confin aconf/directory next todocker-compose.yml. Start fromconf/app.conf. -
Start the services:
docker-compose up -
Open
http://localhost:8000, set the password ofadminon the Welcome to Casdoor page, and sign in asbuilt-in/admin. See Sign in to the admin console.
docker-compose.yml sets the RUNNING_IN_DOCKER environment variable. The database is reachable at localhost from the host but not from inside the Casdoor container. When RUNNING_IN_DOCKER is set, Casdoor connects to host.docker.internal instead, so you don't have to edit app.conf.
Check the container health
Both images define a Docker HEALTHCHECK. Every 10 seconds, it requests http://127.0.0.1:<httpport>/api/health inside the container, where <httpport> is the httpport environment variable or 8000. The check times out after 5 seconds, allows 60 seconds for startup, and marks the container unhealthy after 3 failures in a row. If you change the port only in a mounted app.conf, the check still requests port 8000, so set httpport as an environment variable instead.
-
List the containers:
docker psThe
STATUScolumn shows(healthy)once Casdoor answers, and(unhealthy)when it stops answering.