Caddy that routes, issues certificates and creates Cloudflare DNS records from Docker labels
184
Caddy that routes, issues certificates and creates Cloudflare DNS records from Docker labels
Put the global options in a base Caddyfile. The zone line also manages the listed record (host1.example.com here), so don't list @ unless the apex should point at this host:
{
acme_dns cloudflare {env.CLOUDFLARE_API_TOKEN}
dynamic_dns {
provider cloudflare {env.CLOUDFLARE_API_TOKEN}
domains {
example.com host1
}
dynamic_domains
}
}
Then label each container with its site address:
services:
caddy:
image: tomy0000000/caddy-docker-proxy
ports:
- "80:80"
- "443:443"
environment:
CADDY_DOCKER_CADDYFILE_PATH: /etc/caddy/Caddyfile
CADDY_INGRESS_NETWORKS: caddy
CLOUDFLARE_API_TOKEN: <api_token>
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./Caddyfile:/etc/caddy/Caddyfile
- data:/data
whoami:
image: traefik/whoami
labels:
caddy: whoami.example.com
caddy.reverse_proxy: "{{upstreams 80}}"
networks:
default:
external: true
name: caddy
volumes:
data:
Obtain token from https://dash.cloudflare.com/profile/api-tokens. The token must have permission to edit Zone example.com.
The entrypoint is op run, which replaces op:// references in the environment when the container starts. Set a service account token, and reference the secret instead of pasting it:
environment:
OP_SERVICE_ACCOUNT_TOKEN: ${OP_SERVICE_ACCOUNT_TOKEN}
CLOUDFLARE_API_TOKEN: op://Develop/Cloudflare API Token/credential
Without OP_SERVICE_ACCOUNT_TOKEN, plain values pass through unchanged. Restart the container to pick up a rotated secret.
Content type
Image
Digest
sha256:13dff1349…
Size
67 MB
Last updated
1 day ago
docker pull tomy0000000/caddy-docker-proxy