Skip to content

How to setup Caddy (with Docker)

Untested

Folders

Create the folder structure.

# Create main service directory
mkdir -p /home/dan/services

# Create the Caddy directories
mkdir -p /home/dan/services/caddy/{config,data}

Caddyfile

cd /home/dan/services
nano Caddyfile

Paste the following content:

{
    # uncomment the next line if you plan on using grafana and prometheus
    # metrics 

    log {
        # can also be format json
        format console {
            time_format iso8601
        }
    }
}

Docker

  1. Create the Docker Compose File

    nano docker-compose.yml
    

    Paste the following content:

    services:
      caddy:
        image: caddy:alpine
        restart: unless-stopped
        container_name: caddy
        volumes:
          - ./Caddyfile:/etc/caddy/Caddyfile
          - ./caddy/config:/config
          - ./caddy/data:/data
        network_mode: "host"
    

  2. Download and start the caddy docker service:

    docker compose up -d caddy
    
  3. Check if Caddy was able to start successfully.

    docker ps
    

    If something doesn't look right, you can inspect the logs:

    bash docker compose logs -f caddy