Skip to content

Instantly share code, notes, and snippets.

@undernewmanagement
Created January 29, 2020 01:07
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save undernewmanagement/414ce52ae4bd020115e849eaef7c54dd to your computer and use it in GitHub Desktop.
Save undernewmanagement/414ce52ae4bd020115e849eaef7c54dd to your computer and use it in GitHub Desktop.
Pristine config for Traefik 2.0, Docker, and LetsEncrypt with sample container. Includes a HTTP to HTTPS redirect
version: '3'
services:
traefik:
container_name: traefik
image: traefik:v2.0
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--entryPoints.web.address=:80"
- "--entryPoints.websecure.address=:443"
- "--certificatesResolvers.le.acme.email=<YOUR_EMAIL>"
- "--certificatesResolvers.le.acme.storage=acme.json"
- "--certificatesResolvers.le.acme.tlsChallenge=true"
- "--certificatesResolvers.le.acme.httpChallenge=true"
- "--certificatesResolvers.le.acme.httpChallenge.entryPoint=web"
restart: always
ports:
- 80:80
- 443:443
- 8080:8080
networks:
- web
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./acme.json:/acme.json
labels:
# Redirect all HTTP to HTTPS permanently
- traefik.http.routers.http_catchall.rule=HostRegexp(`{any:.+}`)
- traefik.http.routers.http_catchall.entrypoints=web
- traefik.http.routers.http_catchall.middlewares=https_redirect
- traefik.http.middlewares.https_redirect.redirectscheme.scheme=https
- traefik.http.middlewares.https_redirect.redirectscheme.permanent=true
whoami:
image: "containous/whoami"
container_name: "simple-service"
restart: always
networks:
- web
labels:
- traefik.http.routers.whoami.rule=Host(`<YOUR_DOMAIN_NAME>`)
- traefik.http.routers.whoami.tls=true
- traefik.http.routers.whoami.tls.certresolver=le
networks:
web:
external: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment