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.
Don't want to run it yourself? Casdoor Cloud gives you a dedicated Casdoor instance that we host and keep upgraded for you, from $29/month with no per-user fees. New accounts get $20 in free credit to try it.
Choose an image
Casdoor publishes two images on Docker Hub:
| Image produit | 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. -
Sign in with the organization
built-in, the usernameadmin, and the password123.
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.
-
Open
http://localhost:8000and sign in asbuilt-in/adminwith the password123.
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:8000and sign in asbuilt-in/adminwith the password123.
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 database.
-
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:8000and sign in asbuilt-in/adminwith the password123.
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.Next steps
- Change the password of
built-in/adminbefore you expose Casdoor to a network. - Deploy with Docker in production
- Connect an application to Casdoor