All tools / Docker Compose examples
Traefik reverse proxy with Let's Encrypt with Docker Compose
Traefik routing to containers by label, redirecting HTTP to HTTPS and fetching Let's Encrypt certificates, with a sample whoami service.
compose.yaml
services:
traefik:
image: traefik:v3.4
restart: unless-stopped
command:
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:80
- --entrypoints.web.http.redirections.entrypoint.to=websecure
- --entrypoints.web.http.redirections.entrypoint.scheme=https
- --entrypoints.websecure.address=:443
- --certificatesresolvers.le.acme.email=you@example.com
- --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
- --certificatesresolvers.le.acme.httpchallenge.entrypoint=web
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- letsencrypt:/letsencrypt
whoami:
image: traefik/whoami
restart: unless-stopped
labels:
- traefik.enable=true
- traefik.http.routers.whoami.rule=Host(`whoami.example.com`)
- traefik.http.routers.whoami.entrypoints=websecure
- traefik.http.routers.whoami.tls.certresolver=le
volumes:
letsencrypt:
How to use it
Commands
docker compose up -d docker compose ps docker compose logs -f
- Point the domain's DNS at this server and open ports 80 and 443. Route your own containers by copying the whoami labels.
- Traefik reads the Docker socket to discover containers; keep it read-only as shown.