I'm expecting the following to redirect all requests to reddit.com , but instead it returns a 404. What is wrong here?
version: "2"
services:
traefik:
image: traefik:2.1
container_name: "traefik"
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
labels:
- "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
- "traefik.http.routers.http-catchall.entrypoints=web"
- "traefik.http.routers.http-catchall.middlewares=redirect-to-reddit@docker"
- "traefik.http.middlewares.redirect-to-reddit.redirectregex.regex=^http://.*"
- "traefik.http.middlewares.redirect-to-reddit.redirectregex.replacement=http://reddit.com"
I note that if I instead add an additional docker container/service, for example containous/whoami, and move the labels from traefik to whoami, then the global catchall works as expected...
ldez
January 11, 2020, 9:44pm
3
Hello,
It's because you forget to put traefik.enable=true
label on the container.
As you are using --providers.docker.exposedbydefault=false
this label is mandatory.
https://docs.traefik.io/v2.1/routing/providers/docker/#traefikenable
version: "3.7"
services:
traefik:
image: traefik:v2.1.2
container_name: traefik
command:
- --api.insecure=true
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:80
ports:
- 80:80
- 8080:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
labels:
traefik.enable: true
traefik.http.routers.http-catchall.rule: hostregexp(`{host:.+}`)
traefik.http.routers.http-catchall.entrypoints: web
traefik.http.routers.http-catchall.middlewares: redirect-to-reddit@docker
traefik.http.middlewares.redirect-to-reddit.redirectregex.regex: ^http://(.+)
traefik.http.middlewares.redirect-to-reddit.redirectregex.replacement: http://reddit.com
How to do that when running Traefik inside of kubernetes?