跳到主内容

Deploying to Docker

In this chapter, you will learn how to deploy Casdoor using Docker and Docker Compose with various reverse proxy configurations.

Prerequisites

Before starting, ensure you have:

  • Docker installed on your system
  • Docker Compose installed (for compose method)
  • A domain name pointing to your server (for reverse proxy configurations)

Docker Deployment Methods

Choose your preferred deployment method:

Using Docker Compose

Create a docker-compose.yml file:

services:
casdoor:
image: casdoor/casdoor:latest
container_name: casdoor
restart: unless-stopped
ports:
- "8000:8000"
environment:
- GIN_MODE=release
volumes:
- ./conf:/conf
- ./logs:/logs
networks:
- casdoor-network

networks:
casdoor-network:
driver: bridge

Start the service:

docker-compose up -d

Reverse Proxy Configuration

For production deployments, it's recommended to use a reverse proxy with TLS certificates. Choose your preferred reverse proxy:

Traefik with Docker Labels

Create a docker-compose.yml with Traefik labels:

services:
traefik:
image: traefik:v2.10
container_name: traefik
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik/acme.json:/acme.json
command:
- --api.dashboard=true
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
- --certificatesresolvers.letsencrypt.acme.email=your-email@example.com
- --certificatesresolvers.letsencrypt.acme.storage=/acme.json
- --certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web
networks:
- casdoor-network

casdoor:
image: casdoor/casdoor:latest
container_name: casdoor
restart: unless-stopped
environment:
- GIN_MODE=release
volumes:
- ./conf:/conf
- ./logs:/logs
labels:
- "traefik.enable=true"
- "traefik.http.routers.casdoor.rule=Host(`your-domain.com`)"
- "traefik.http.routers.casdoor.entrypoints=websecure"
- "traefik.http.routers.casdoor.tls.certresolver=letsencrypt"
- "traefik.http.services.casdoor.loadbalancer.server.port=8000"
networks:
- casdoor-network

networks:
casdoor-network:
driver: bridge

Create the acme.json file:

touch traefik/acme.json
chmod 600 traefik/acme.json

Configuration

Create the necessary configuration directories

mkdir -p conf logs

Download the Casdoor configuration files

wget https://raw.githubusercontent.com/casdoor/casdoor/master/conf/app.conf -O conf/app.conf
wget https://raw.githubusercontent.com/casdoor/casdoor/master/conf/init_data.json -O conf/init_data.json

Edit conf/app.conf to match your environment settings

Testing

After deployment, visit your domain in your browser:

  • Docker Run/Compose only: http://your-server-ip:8000
  • With Reverse Proxy: https://your-domain.com

Troubleshooting

Check container logs

# For docker-compose
docker-compose logs casdoor

# For docker run
docker logs casdoor

Verify reverse proxy configuration

# Check if containers are running
docker ps

# Test connectivity
curl -I http://localhost:8000

SSL Certificate Issues

  • Ensure your domain points to the correct server IP
  • Check that ports 80 and 443 are open in your firewall
  • Verify DNS propagation with nslookup your-domain.com