Last active
February 19, 2021 07:19
-
-
Save lepinkainen/73a39c5f7b5385baf14b9f6a5f3ff685 to your computer and use it in GitHub Desktop.
Traefik setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Traefik compose file | |
services: | |
reverse-proxy: | |
# The official v2.1 Traefik docker image | |
image: traefik:v2.2.1 | |
container_name: traefik | |
# Enables the web UI and tells Traefik to listen to docker | |
command: | |
- --log.level=INFO | |
- --api=true | |
- --providers.docker=true | |
- --providers.docker.exposedbydefault=false | |
- --providers.docker.network=traefik | |
- --entrypoints.web.address=:80 | |
- --entrypoints.websecure.address=:443 | |
- --ping | |
- --certificatesresolvers.mytlschallenge.acme.tlschallenge=true | |
- [email protected] | |
- --certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json | |
ports: | |
- 80:80 | |
- 443:443 | |
healthcheck: | |
test: traefik healthcheck --ping | |
volumes: | |
# So that Traefik can listen to the Docker events | |
- /var/run/docker.sock:/var/run/docker.sock:ro | |
- ./letsencrypt:/letsencrypt | |
- ./config:/config:ro | |
labels: | |
- traefik.enable=true | |
- traefik.http.routers.http-catchall.rule=hostregexp(`{host:[a-zA-Z0-9-.]+}`) | |
- 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 | |
- traefik.http.routers.api.rule=Host(`traefik.example.com`) | |
- traefik.http.routers.api.service=api@internal | |
- traefik.http.routers.api.middlewares=auth | |
- traefik.http.routers.api.entrypoints=websecure | |
- traefik.http.routers.api.tls.certresolver=mytlschallenge | |
- traefik.http.middlewares.auth.basicauth.usersfile=/config/users | |
networks: | |
- traefik | |
restart: unless-stopped | |
networks: | |
traefik: | |
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# whoami container | |
services: | |
whoami: | |
image: containous/whoami | |
container_name: whoami | |
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=mytlschallenge | |
- traefik.frontend.port=80 | |
networks: | |
- traefik | |
restart: 'unless-stopped' | |
networks: | |
traefik: | |
external: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment