Is there a way around this configuration nightmare? (It took me many hours to figure this out!)
version: "3.7"
services:
web:
image: my/app
networks:
- traefik
deploy:
labels:
# Traefik V1
traefik.enable: "true"
traefik.frontend.rule: "Host:example.com"
traefik.docker.network: traefik_traefik
traefik.port: 8000
# Traefik V2
traefik.enable: "true"
traefik.docker.network: traefik_traefik
traefik.http.middlewares.example-web-compress.compress: "true"
traefik.http.middlewares.example-web-redirectscheme.redirectscheme.scheme: https
traefik.http.routers.example-web.entrypoints: web
traefik.http.routers.example-web.rule: Host(`example.com`)
traefik.http.routers.example-web.middlewares: example-web-redirectscheme@docker
traefik.http.routers.example-web-secured.entrypoints: web-secure
traefik.http.routers.example-web-secured.rule: Host(`example.com`)
traefik.http.routers.example-web-secured.middlewares: example-web-compress@docker
traefik.http.routers.example-web-secured.tls.certResolver: letsencrypt
traefik.http.routers.example-web-secured.tls.domains[0].main: "example.com"
traefik.http.routers.example-web-secured.tls.domains[0].sans: "*.example.com"
traefik.http.services.example-web.loadbalancer.server.port: 8000
ldez
2
Hello,
You can use something like that:
version: "3.7"
services:
traefik:
image: traefik:v2.0.4
command:
- "--api=true"
- "--providers.docker"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.web-secure.address=:443"
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
labels:
traefik.enable: "true"
# global redirect HTTPS
traefik.http.routers.redirecttohttps.rule: HostRegexp(`{any:.+}`)
traefik.http.routers.redirecttohttps.entryPoints: web
traefik.http.routers.redirecttohttps.middlewares: redirecthttps
# Dashboard
traefik.http.routers.api.rule: Host(`traefik.localhost`)
traefik.http.routers.api.service: api@internal
traefik.http.routers.api.entryPoints: web
# Middlewares
traefik.http.middlewares.example-web-compress.compress: "true"
traefik.http.middlewares.redirecthttps.redirectScheme.scheme: https
# noop service (only for Docker Swarm)
traefik.http.services.noop.loadbalancer.server.port: 999
services:
web:
image: containous/whoami:v1.4.0
deploy:
labels:
# Traefik v1
# traefik.enable: "true"
# traefik.frontend.rule: "Host:example.com"
# traefik.docker.network: traefik_traefik
# traefik.port: 8000
# Traefik v2
traefik.enable: "true"
traefik.docker.network: traefik_traefik
traefik.http.routers.example-web-secured.rule: Host(`example.com`)
traefik.http.routers.example-web-secured.entrypoints: web-secure
traefik.http.routers.example-web-secured.middlewares: example-web-compress@docker
traefik.http.routers.example-web-secured.tls.certResolver: letsencrypt
traefik.http.routers.example-web-secured.tls.domains[0].main: "example.com"
traefik.http.routers.example-web-secured.tls.domains[0].sans: "*.example.com"
traefik.http.services.example-web.loadbalancer.server.port: 80
1 Like
@Idez That's quite an improvement. Thanks!