Traefik in Docker: Path routing not working

Viewed 2056

I am trying to setup traefik in a container on a docker host: Host: myserver.some.domain Traefik: v2.1.3 Docker Host: v19.03.8

I want to view the dashboard when I request "http://myserver.some.domain/traefik" and further navigation should be reflected in the url like requesting the first url and landing on "http://myserver.some.domain/traefik/dashboard/#/". I experimented with multiple middleswares:

  • Path
  • PathPrefix
  • StripPrefix

So far PathPrefix sounds like the most correct choice, but I get "404 page not found". For now I exposed also port 8080, so I can crosscheck my changes (on http://myserver.some.domain:8080, which works). Later on, I want to hide port 8080 and only let the routing on port 80 do the work.

My docker-compose.yml looks like this:

version: "3"

services:
  traefik:
    image: traefik:2.1.3
    container_name: 'traefik'
    command:
      # Enable DEBUG log for issue resolving
      - "--log.level=DEBUG"
      # Enable dashboard
      - "--api.dashboard=true"
      # Enable debug information in api
      - "--api.debug=true"
      # Allow api access on unsecure http requests
      # Will be removed when SSL will be configured
      - "--api.insecure=true"
      # Default http port
      - "--entrypoints.web.address=:80"
      # Dashboard port
      - "--entrypoints.traefik.address=:8080"
      # Allow traefik to se other docker containers for dynamic routing
      - "--providers.docker.endpoint=unix:///var/run/docker.sock"
      # Hide containers without traefik configuration by default
      - "--providers.docker.exposedByDefault=false"
      # Use the container's configured network
      # All containers use network "proxy", type "bridge"
      - "--providers.docker.useBindportIP=false"
    labels:
      # Enable Traefik configuration for container
      traefik.enable: "true"
      # Use docker network "proxy"
      traefik.docker.network: "proxy"
      # Define http entrypoint
      traefik.http.routers.traefik.entrypoints: "web"
      # Proxy all requests which start with "/traefik"
      traefik.http.routers.traefik.rule: "PathPrefix(`/traefik`)"
#      # Proxy request on path "/traefik"
#      traefik.http.routers.traefik.rule: "Path(`/traefik`)"
      # Replace path prefix "/traefik" with "/"
      traefik.http.routers.traefik.middlewares: "traefik_replacepath"
      traefik.http.middlewares.traefik_replacepath.replacePath.path: "/"
#      # Strip path prefix "/traefik" and force slash "/"
#      traefik.http.routers.traefik.middlewares: "traefik_stripprefix"
#      traefik.http.middlewares.traefik_stripprefix.stripprefix.prefices: "/traefik"
#      traefik.http.middlewares.traefik_stripprefix.stripPrefix.forceSlash: "true"
      # Define port for service
      traefik.http.services.traefik.loadbalancer.server.port: "8080"
    volumes:
      # Allow traefik to see other containers
      - "/var/run/docker.sock:/var/run/docker.sock"
    networks:
      - proxy
    ports:
      # Expose port 80 to handle web/http requests
      - "80:80"
      # For DEBUG: Expose port 8080 to see dashboard without routing
      # Will be removed when default rounting is working
      - "8080:8080"

networks:
  proxy:
    external: true

Anybody knows where I am wrong?

Best regards, David

0 Answers
Related