Skip to content

Instantly share code, notes, and snippets.

@sqbs
Forked from darth-veitcher/docker-compose.yaml
Last active June 19, 2024 04:08
Show Gist options
  • Save sqbs/73e1788c14776a9f65392368ad3ca389 to your computer and use it in GitHub Desktop.
Save sqbs/73e1788c14776a9f65392368ad3ca389 to your computer and use it in GitHub Desktop.
Traefik v2.2 with Cloudflare Wildcard
version: "3"
services:
traefik:
image: "traefik:v2.2"
container_name: "traefik"
command:
# Globals
- "--log.level=DEBUG"
- "--api=true"
- "--global.sendAnonymousUsage=false"
# Docker
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.endpoint=unix:///var/run/docker.sock"
# Entrypoints
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
# LetsEncrypt
- "--certificatesresolvers.mydnschallenge.acme.email=${CF_API_EMAIL}"
- "--certificatesresolvers.mydnschallenge.acme.dnschallenge.provider=cloudflare"
- "--certificatesresolvers.mydnschallenge.acme.storage=/etc/traefik/acme.json"
ports:
- "80:80"
- "443:443"
environment:
- CF_API_EMAIL=${CF_API_EMAIL}
- CF_API_KEY=${CF_API_KEY}
volumes:
- "/etc/traefik/acme.json:/etc/traefik/acme.json"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
labels:
# API
- "traefik.enable=true"
- "traefik.http.routers.traefik.rule=Host(`traefik.mydomain.fyi`)"
- "traefik.http.services.traefik.loadbalancer.server.port=8080"
- "traefik.http.services.traefik.loadbalancer.server.scheme=http"
# Wildcard cert
- "traefik.http.routers.traefik.tls.domains[0].main=mydomain.fyi"
- "traefik.http.routers.traefik.tls.domains[0].sans=*.mydomain.fyi"
- "traefik.http.routers.traefik.tls.certresolver=mydnschallenge"
# Global http-->https
- "traefik.http.routers.http-catchall.rule=hostregexp(`{host:[a-z-.]+}`)"
- "traefik.http.routers.http-catchall.entrypoints=web"
- "traefik.http.routers.http-catchall.middlewares=redirect-to-https"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
# BasicAuth Middleware
- "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
- "traefik.http.routers.traefik.middlewares=auth"
whoami:
image: "containous/whoami"
container_name: "whoami"
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`whoami.mydomain.fyi`)"
- "traefik.http.routers.whoami.entrypoints=websecure"
- "traefik.http.routers.whoami.tls.certresolver=mydnschallenge"
- "traefik.http.routers.whoami.middlewares=auth"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment