Routing paths with Traefik Routing paths with Traefik docker docker

Routing paths with Traefik


This morning I found the solution. The correct approach in cases like these should be to use the PathPrefixStrip rule. However, as mentioned here, putting a / at the end of the rule will break the setup. I created a working configuration by removing / at the end of the PathPrefixStrip: /portainer4/ rule. So this docker-compose configuration worked for me:

version: '2'services:  traefik:    container_name: traefik2    image: traefik    command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG    ports:      - "80:80"      - "8081:8080"    volumes:      - /var/run/docker.sock:/var/run/docker.sock      - /dev/null:/traefik.toml    labels:        - "traefik.enable=false"  portainer:    image: portainer/portainer    labels:      - "traefik.backend=portainer"      - "traefik.frontend.rule=PathPrefixStrip: /portainer"

Now when I navigate to <myIP>/portainer/ I see the portainer page. I do, however, still get the white page as mentioned earlier when I navigate to <myIP>/portainer.


for future googler

The reason it doesn't work without slash is an existing issue

https://github.com/containous/traefik/issues/563

For v2 docker label

      - "traefik.http.routers.portainer-secure.rule=Host(`your-domain.com`) && PathPrefix(`/portainer`)"      - "traefik.http.routers.portainer-secure.middlewares=portainer-redirectregex, portainer-replacepathregex"      - "traefik.http.middlewares.portainer-replacepathregex.replacepathregex.regex=^/portainer/(.*)"      - "traefik.http.middlewares.portainer-replacepathregex.replacepathregex.replacement=/$$1"      - "traefik.http.middlewares.portainer-redirectregex.redirectregex.regex=^(.*)/portainer$$"      - "traefik.http.middlewares.portainer-redirectregex.redirectregex.replacement=$$1/portainer/"