Caddy with Docker

Caddy server

As a longtime user of Traefik, I was pleasantly surprised when I tripped over Caddy. It’s another proxy application like Traefik that ticks all the boxes. Reverse proxy, routing, https, open source, container based, easy to use. And that last one is crucial.

Basic Caddy config

There are a few volumes at play.

  • caddy : the Caddy and Compose root
  • caddy/Caddyfile : the centre of the universe
  • caddy/data : the house for certificates (optional)
  • caddy/config : JSON config files (optional)
version: "3"

networks:
        web:
                external: true

services:
        caddy:
                image: caddy:2-alpine
                restart: unless-stopped
                ports:
                        - "80:80"
                        - "443:443"
                volumes:
                        - /data/caddy/Caddyfile:/etc/caddy/Caddyfile
                        - /data/caddy/data:/data
                        - /data/caddy/config:/config
                networks:
                        - web

Caddy will function with only the Caddyfile mapped, and is fine for testing, but having the data and config volumes allows externalising of some key files, for backup or consistency when upgrading the core container image.

Caddyfile

{
    # Global options block. Entirely optional, https is on by default
    # Optional email key for lets encrypt
    email youremail@domain.com 
    # Optional staging lets encrypt for testing. Comment out for production.
    # acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
}
my.mydomain.com {
    reverse_proxy xxx:8888
}
www.my.mydomain.com {
    redir https://my.mydomain.com{uri}
}

more from original post