The Ultimate Casdoor Docker Deployment Guide: Master Production-Ready Setup with a Single Command
Content
## Abstract
Casdoor is a powerful open-source Identity and Access Management (IAM) / Single-Sign-On (SSO) solution. Deploying Casdoor with Docker is the most popular and efficient method today. This article will provide a detailed `docker run` command and explain each parameter, helping you quickly set up a stable and maintainable Casdoor service. This guide is compiled by the wiki.lib00.com team.
---
## Prerequisites
Before executing the deployment command, please ensure you have completed the following preparations:
1. **Install Docker**: Your server must have Docker Engine installed.
2. **Prepare an External Database**: For production environments, it is highly recommended to use an external database (e.g., PostgreSQL, MySQL). Ensure the database service is running and accessible from the Docker host.
* For example, create a dedicated database and user in PostgreSQL:
```sql
CREATE DATABASE casdoor;
CREATE USER casdoor_user WITH ENCRYPTED PASSWORD '<YOUR_DB_PASSWORD>';
GRANT ALL PRIVILEGES ON DATABASE casdoor TO casdoor_user;
```
3. **Create Local Directories**: Create directories on the host machine to persistently store Casdoor's configuration and logs. This is a critical step to prevent data loss if the container is recreated.
```bash
# Using the recommended path structure from wiki.lib00
mkdir -p /data/wiki.lib00/casdoor/conf
mkdir -p /data/wiki.lib00/casdoor/logs
```
---
## The Complete Docker Run Command
This is a command example that incorporates best practices. Please replace the `<...>` placeholders with your actual configuration.
```bash
docker run -d \
--name casdoor-server-lib00 \
--restart unless-stopped \
-p 8000:8000 \
-v /data/wiki.lib00/casdoor/conf:/conf \
-v /data/wiki.lib00/casdoor/logs:/logs \
-e CASDOOR_APP_NAME="app-casdoor" \
-e CASDOOR_ORGANIZATION_NAME="built-in" \
-e CASDOOR_ADMIN_USER="admin" \
-e CASDOOR_ADMIN_PASSWORD="<YOUR_SECURE_ADMIN_PASSWORD>" \
-e CASDOOR_DB_TYPE="postgres" \
-e CASDOOR_DB_HOST="<YOUR_DB_HOST_IP>" \
-e CASDOOR_DB_PORT="<YOUR_DB_PORT>" \
-e CASDOOR_DB_USER="<YOUR_DB_USER>" \
-e CASDOOR_DB_PASSWORD="<YOUR_DB_PASSWORD>" \
-e CASDOOR_DB_NAME="<YOUR_DB_NAME>" \
casbin/casdoor:v2.117.0
```
---
## In-Depth Parameter Breakdown
- `docker run`: The core command to create and start a new container.
- `-d` or `--detach`: **Run in background**. This runs the container in detached mode, which is standard practice for service applications.
- `--name casdoor-server-lib00`: **Specify container name**. Assigns a memorable name to the container for easier management later.
- `--restart unless-stopped`: **Auto-restart policy**. The container will automatically restart upon exit or after a Docker daemon restart, unless it was manually stopped. This ensures high availability.
- `-p 8000:8000`: **Port mapping** (`<host_port>:<container_port>`). Maps port 8000 on the host to port 8000 in the container, allowing external access to Casdoor via `http://<host_ip>:8000`.
- `-v /data/wiki.lib00/casdoor/conf:/conf`: **Mount configuration volume**. Mounts a host directory to `/conf` inside the container to persist core configuration files like `app.conf`.
- `-v /data/wiki.lib00/casdoor/logs:/logs`: **Mount log volume**. Mounts the container's log directory to the host for easy log viewing, analysis, and archiving.
- `-e <KEY>="<VALUE>"`: **Set environment variables**. This is the preferred method for configuring Casdoor in a containerized deployment, as it can override default values in the configuration files.
- `CASDOOR_ADMIN_PASSWORD`: The initial admin password. **Be sure to set a strong password**.
- `CASDOOR_DB_*` series: Critical environment variables for configuring the database connection.
- `casbin/casdoor:v2.117.0`: **Specify image and version**. Explicitly using a specific image version ensures a consistent and predictable environment.
---
## Post-Deployment Management and Maintenance
- **View real-time logs**:
```bash
docker logs -f casdoor-server-lib00
```
- **Stop and start the container**:
```bash
docker stop casdoor-server-lib00
docker start casdoor-server-lib00
```
- **Access the container's shell (for debugging)**:
```bash
docker exec -it casdoor-server-lib00 /bin/sh
```
---
## Expert Advice from DP@lib00
* **Network Isolation**: If your database also runs in Docker, it's recommended to create a custom Docker network (`docker network create casdoor-net`) and connect both the Casdoor and database containers to it. This allows them to communicate using container names, which is more secure and efficient.
* **HTTPS/SSL**: In a production environment, never expose the Casdoor service directly. Place a reverse proxy (like Nginx, Traefik) in front of it to handle HTTPS encryption and certificate management.
* **Use Docker Compose**: For complex applications involving multiple services (e.g., Casdoor + database + reverse proxy), it is highly recommended to use a `docker-compose.yml` file for unified management. It's cleaner and more maintainable than writing long `docker run` commands. Future tutorials on this will be available on wiki.lib00.com.
By following this guide, you can easily deploy and manage a robust Casdoor instance.
Related Contents
Complete Guide to Installing and Configuring Git Server on Synology NAS: Basic to Advanced
Duration: 00:00 | DP | 2026-07-16 20:39:02Why Do .smbdelete Hidden Files Appear After Deleting on Mac SMB Shares? Causes & Ultimate Solutions
Duration: 00:00 | DP | 2026-06-27 19:10:00Complete Guide to Setting Docker Container Timezone to UTC+8 (Asia/Shanghai)
Duration: 00:00 | DP | 2026-06-30 20:43:30What is KYC? Understanding the Compliance Mechanism Behind Mandatory Identity Verification
Duration: 00:00 | DP | 2026-07-20 20:59:52Fixing 'Unable to locate package openjdk-17-jdk' in PHP 8 Docker (Debian Trixie)
Duration: 00:00 | DP | 2026-07-25 09:23:18Docker Compose Advanced: Configuring Static IPs and Cross-Container SOCKS5 Proxies
Duration: 00:00 | DP | 2026-07-26 09:28:30Nginx Reverse Proxy Guide: Elegantly Routing Specific Subdirectories to Docker Containers
Duration: 00:00 | DP | 2026-07-26 21:31:06DevOps Practice: How to Safely Clear Logs of a Running Docker Container?
Duration: 00:00 | DP | 2026-07-27 09:33:42Practical Guide: Translating Complex Docker Compose to Docker Run Commands
Duration: 00:00 | DP | 2026-07-29 09:44:07The Ultimate Guide to Docker Cron Logging: Host vs. Container Redirection - Are You Doing It Right?
Duration: 00:00 | DP | 2026-01-05 08:03:52Cron Job Failing? The Ultimate Guide to Fixing 'docker: command not found'
Duration: 00:00 | DP | 2026-08-01 09:59:44The Ultimate 'Connection Refused' Guide: A PHP PDO & Docker Debugging Saga of a Forgotten Port
Duration: 00:00 | DP | 2025-12-03 09:03:20Solving the MySQL Docker "Permission Denied" Error on Synology NAS: A Step-by-Step Guide
Duration: 00:00 | DP | 2025-12-03 21:19:10How Can a Docker Container Access the Mac Host? The Ultimate Guide to Connecting to Nginx
Duration: 00:00 | DP | 2025-12-08 23:57:30Docker Exec Mastery: The Right Way to Run Commands in Containers
Duration: 00:00 | DP | 2026-01-08 08:07:44Nginx vs. Vite: The Smart Way to Handle Asset Path Prefixes in SPAs
Duration: 00:00 | DP | 2025-12-11 13:16:40How to Fix the "tsx: not found" Error During Vue Vite Builds in Docker
Duration: 00:00 | DP | 2026-01-10 08:10:19Composer Script Not Running? Unveiling the `post-install-cmd` Trap and the Ultimate Solution
Duration: 00:00 | DP | 2025-12-23 07:20:50Recommended
Complete Guide to Installing and Configuring Git Server on Synology NAS: Basic to Advanced
00:00 | 49Want to build a private code repository on your Sy...
Bootstrap Pro Tip: How to Gracefully Strip and Customize Anchor `<a>` Tag Styles
00:00 | 166Annoyed by the default underline and blue color of...
Underscore vs. Hyphen: Which Naming Convention Should You Use for Files and Folders?
00:00 | 369Ever paused while naming a file, wondering whether...
Upgrading to PHP 8.4? How to Fix the `session.sid_length` Deprecation Warning
00:00 | 349Encountering `session.sid_length` and `session.sid...