跳到主内容

(可选) 使用 Docker 运行

安装要求

硬件

If you want to build the Docker image yourself, please ensure that your machine has at least 2GB of memory. Casdoor's frontend is an NPM project of React. Building the frontend requires at least 2GB of memory. Having less than 2GB of memory may result in a frontend build failure.

If you only need to run the pre-built image, please ensure that your machine has at least 100MB of memory.

操作系统

All operating systems (Linux, Windows, and macOS) are supported.

Docker

You can use Docker (docker-engine version >= 17.05) in Linux or Docker Desktop in Windows and macOS.

Regardless of the operating system, users must ensure that they have docker-engine version >= 17.05. This is because we utilize the multi-stage build feature in the docker-compose.yml, which is supported in versions 17.05 and above. For more information, see https://docs.docker.com/develop/develop-images/multistage-build/.

If you are also using docker-compose, please ensure that you have docker-compose version >= 2.2. For Linux users, you also need to make sure that docker-compose is installed, as it is separate from docker-engine.

获取镜像

我们提供了两个DockerHub 镜像:

名称描述建议
casdoor-all-in-oneBoth Casdoor and a MySQL database are included in the imageThis image already includes a toy database and is only for testing purposes
casdoorOnly Casdoor is included in the imageThis image can be connected to your own database and used in production
  1. casbin/casdoor-all-in-one: This image includes the casdoor binary, a MySQL database, and all the necessary configurations. It is designed for new users who want to try Casdoor quickly. With this image, you can start Casdoor immediately with just one or two commands, without any complex configuration. However, please note that we do not recommend using this image in a production environment.

选项 1: 使用示例数据库

Run the container with port 8000 exposed to the host. The image will be automatically pulled if it doesn't exist on the local host.

docker run -p 8000:8000 casbin/casdoor-all-in-one
注意事项

Some users in areas like China usually use Docker image mirror services like Alibaba Cloud Image Booster (English) to achieve higher download speeds compared to DockerHub. However, these services have a known issue where the latest tag provided by them is not up-to-date. As a result, fetching the latest tag may result in a very old image. To mitigate this issue, you can specify the image version number explicitly using the following command:

docker pull casbin/casdoor-all-in-one:$(curl -sS "https://hub.docker.com/v2/repositories/casbin/casdoor-all-in-one/tags/?page_size=1&page=2" | sed 's/,/,\n/g' | grep '"name"' |awk -F '"' '{print $4}')

Note: The above command utilizes Linux tools like curl, sed, grep, and awk. 如果您正在使用 Windows,请确保您在 Linux 样式外壳中运行,如 Git ShellCygwinCMDPowerShell 将无法工作。

Visit http://localhost:8000 in your browser. Log into the Casdoor dashboard with the default global admin account: built-in/admin

admin
123

选项 2: 使用 docker-compose

注意事项

Some users in areas like China usually use Docker image mirror services like Alibaba Cloud Image Booster (English) to achieve higher download speeds compared to DockerHub. However, these services have a known issue where the latest tag provided by them is not up-to-date. As a result, fetching the latest tag may result in a very old image. To mitigate this issue, you can specify the image version number explicitly using the following command:

docker pull casbin/casdoor:$(curl -sS "https://hub.docker.com/v2/repositories/casbin/casdoor/tags/?page_size=1&page=2" | sed 's/,/,\n/g' | grep '"name"' |awk -F '"' '{print $4}')

Note: The above command utilizes Linux tools like curl, sed, grep, and awk. 如果您正在使用 Windows,请确保您在 Linux 样式外壳中运行,如 Git ShellCygwinCMDPowerShell 将无法工作。

Create a conf/app.conf directory in the same directory level as the docker-compose.yml file. Then, copy app.conf from Casdoor. For more details about app.conf, you can see Via Ini file.

Create a separate database using docker-compose:

docker-compose up

这样就完成了! 🛩️

Visit http://localhost:8000 in your browser. Log into the Casdoor dashboard with the default global admin account: built-in/admin

admin
123

Note: If you dig deeper into the docker-compose.yml file, you may be puzzled by the environment variable we created called "RUNNING_IN_DOCKER". When the database 'db' is created via docker-compose, it is available on your PC's localhost but not the localhost of the Casdoor container. To prevent you from running into troubles caused by modifying app.conf, which can be quite difficult for a new user, we provided this environment variable and pre-assigned it in the docker-compose.yml. When this environment variable is set to true, localhost will be replaced with host.docker.internal so that Casdoor can access the database.

Option-3: Try directly with the standard image

注意事项

Some users in areas like China usually use Docker image mirror services like Alibaba Cloud Image Booster (English) to achieve higher download speeds compared to DockerHub. However, these services have a known issue where the latest tag provided by them is not up-to-date. As a result, fetching the latest tag may result in a very old image. To mitigate this issue, you can specify the image version number explicitly using the following command:

docker pull casbin/casdoor:$(curl -sS "https://hub.docker.com/v2/repositories/casbin/casdoor/tags/?page_size=1&page=2" | sed 's/,/,\n/g' | grep '"name"' |awk -F '"' '{print $4}')

Note: The above command utilizes Linux tools like curl, sed, grep, and awk. 如果您正在使用 Windows,请确保您在 Linux 样式外壳中运行,如 Git ShellCygwinCMDPowerShell 将无法工作。

提示

If it is not convenient to mount the configuration file to a container, using environment variables is also a possible solution.

example

docker run \
-e driverName=mysql \
-e dataSourceName='user:password@tcp(x.x.x.x:3306)/' \
-p 8000:8000 \
casbin/casdoor:latest

Create conf/app.conf. You can copy it from conf/app.conf in Casdoor. For more details about app.conf, you can see Via Ini file.

然后运行

docker run  -p 8000:8000 -v /folder/of/app.conf:/conf casbin/casdoor:latest

Anyway, just mount the app.conf to /conf/app.conf and start the container.

Visit http://localhost:8000 in your browser. Log into the Casdoor dashboard with the default global admin account: built-in/admin

admin
123