3

I'm trying my best to get Traefik dashboard available through http://gateway.localhost/dashboard/, but I'm always getting a 404 response* from Traefik. Can s.o. please review my stack file and tell me, why it's not working?

I tried it on my server with a valid domain, but it's either working there or on localhost with Docker Desktop in Swarm mode. The WhoAmI service can be reached through http://localhost which is correct.

docker stack deploy -c traefik.yml traefik

*404 is returned for these routes too: http://gateway.localhost, http://gateway.localhost/dashboard

traefik.yml:

version: '3'

services:
  reverse-proxy:
    image: traefik:v2.5
    command:
      - "--providers.docker.swarmmode=true"
      - "--providers.docker.exposedByDefault=false"
      - "--api.dashboard=true"
      - "--entrypoints.web.address=:80"
      # Logging
      - "--accesslog"
      - "--log.level=INFO"
    ports:
      - "80:80"
    deploy:
      labels:
        #Because Swarm API does not support automatic way
        - "traefik.http.services.reverse-proxy.loadbalancer.server.port=80"
        #Dashboard
        - "traefik.http.routers.dashboard.rule=Host(`gateway.localhost`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
        - "traefik.http.routers.dashboard.service=api@internal"
        - "traefik.http.routers.dashboard.entrypoints=web"
        - "traefik.http.routers.dashboard.middlewares=auth"
        - "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
      placement:
        constraints:
          - node.role == manager
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro

  whoami:
    image: traefik/whoami
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.whoami.rule=Host(`localhost`)"
        - "traefik.http.routers.whoami.entrypoints=web"
        - "traefik.http.services.whoami.loadbalancer.server.port=80"
0

1 Answer 1

4

You need to enable traefik for the container with the traefik.enable=true label:

version: '3'

services:
  reverse-proxy:
    image: traefik:v2.5
    command:
      - "--providers.docker.swarmmode=true"
      - "--providers.docker.exposedByDefault=false"
      - "--api.dashboard=true"
      - "--entrypoints.web.address=:80"
      # Logging
      - "--accesslog"
      - "--log.level=INFO"
    ports:
      - "80:80"
    deploy:
      labels:
        ######## add the following label to enable traefik #######
        - "traefik.enable=true"
        #Because Swarm API does not support automatic way
        - "traefik.http.services.reverse-proxy.loadbalancer.server.port=80"
        #Dashboard
        - "traefik.http.routers.dashboard.rule=Host(`gateway.localhost`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
        - "traefik.http.routers.dashboard.service=api@internal"
        - "traefik.http.routers.dashboard.entrypoints=web"
        - "traefik.http.routers.dashboard.middlewares=auth"
        - "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
      placement:
        constraints:
          - node.role == manager
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro

  whoami:
    image: traefik/whoami
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.whoami.rule=Host(`localhost`)"
        - "traefik.http.routers.whoami.entrypoints=web"
        - "traefik.http.services.whoami.loadbalancer.server.port=80"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.