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
The Ultimate Guide to Docker Cron Logging: Host vs. Container Redirection - Are You Doing It Right?
Duration: 00:00 | DP | 2026-01-05 08:03:52The 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:50The Ultimate Guide to Docker Cron Jobs: Effortlessly Scheduling PHP Tasks in Containers from the Host
Duration: 00:00 | DP | 2025-12-29 10:30:50From Phantom Conflicts to Docker Permissions: A Deep Dive into Debugging an Infinite Loop in a Git Hook for an AI Assistant
Duration: 00:00 | DP | 2025-11-09 16:39:00How to Add Port Mappings to a Running Docker Container: 3 Proven Methods
Duration: 00:00 | DP | 2026-02-05 10:16:12PHP Stuck on Loading After Enabling Xdebug? Don't Panic, It Might Be Working Perfectly!
Duration: 00:00 | DP | 2025-11-15 07:03:00From Zero to Platform: Build Your Own GitHub-Level Login System with NextAuth and Casdoor
Duration: 00:00 | DP | 2026-01-27 08:32:15Connecting LobeChat with MinIO: A Simple Guide to Fixing S3 Path-Style Configuration
Duration: 00:00 | DP | 2026-01-28 08:33:32How to Automatically Run Git Clone on Docker Start? 3 Practical Methods Explained
Duration: 00:00 | DP | 2026-02-15 13:47:17How to Easily Fix the "error: externally-managed-environment" in Python
Duration: 00:00 | DP | 2026-01-29 08:34:50The Ultimate Docker & Xdebug Guide: Solving the 'Address Already in Use' Error for Port 9003 with PhpStorm
Duration: 00:00 | DP | 2026-02-18 14:50:37The Ultimate MinIO Docker Deployment Guide: From Public Access to Nginx Reverse Proxy Pitfalls
Duration: 00:00 | DP | 2026-02-24 16:57:16Recommended
How Do You Pronounce Nginx? The Official Guide to Saying It Right: 'engine x'
00:00 | 42Struggling with the correct pronunciation of Nginx...
One-Liner PHP Magic: Securely Filter Arrays with `array_intersect_key` and `array_flip`
00:00 | 38Discover the powerful combination of `array_inters...
Master cURL Timeouts: A Definitive Guide to Fixing "Operation timed out" Errors
00:00 | 51Frequently encountering "cURL Error: Operation tim...
Docker Exec Mastery: The Right Way to Run Commands in Containers
00:00 | 29Running commands inside a Docker container from th...