Traefik and CloudFlare is a modern reverse proxy that securely exposes your applications
Traefik + CloudFlare Docker Compose example
Self-host Traefik + CloudFlare on your own server, homelab, or VPS starting from this Docker Compose example.
It runs Traefik + CloudFlare in Docker containers using the official traefik:latest image, with persistent volumes and automatic restarts preconfigured.
Review the environment variables and adjust them to your setup, save the file as compose.yml (or docker-compose.yml), and start the stack with docker compose up -d.
services:
traefik:
image: traefik:latest
restart: unless-stopped
security_opt:
- no-new-privileges:true
command:
# EntryPoints
- "--entrypoints.web.address=:80"
- "--entrypoints.web.http.redirections.entrypoint.to=websecure"
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
- "--entrypoints.web.http.redirections.entrypoint.permanent=true"
- "--entrypoints.websecure.address=:443"
- "--entrypoints.websecure.http.tls=true"
# Providers
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.network=app_traefik_web"
# Certificates
- "--providers.file.directory=/certs"
- "--providers.file.watch=true"
# Observability
- "--log.level=ERROR"
- "--accesslog=false"
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./certs:/certs:ro
networks:
- app_traefik_web
networks:
app_traefik_web:
external: true Extra files
The Docker Compose configuration above bind-mounts the following file. Save it next to your compose.yml,
keeping the same relative path.
certs/certificates.yml
tls:
certificates:
# Create files "certs/your_domain.cert" and "certs/your_domain.key"
# and mark them as encrypted.
# Uncomment the following lines:
#- certFile: /certs/cloudflare.cert
# keyFile: /certs/cloudflare.key Prefer a managed setup? WinterFlow installs, configures, and updates Traefik + CloudFlare for you using this same Docker Compose configuration.