Dmitriy Lunev
Dmitriy Lunev

Reputation: 227

Traefik Dashboard is empty

I haveve implement traefik in my production (django, postgresql, gunicorn) and all works correct when I use my /api and /admin.

But traefik's dashboard works incorrect (I can sign in and go to /dashboard/, but it shows blank fields.)

enter image description here

log:

web                   | Not Found: /api/overview
me-project-traefik-1  | 78.24.102.87 - - [15/Jun/2022:10:21:42 +0000] "GET /api/overview HTTP/2.0" 404 179 "-" "-" 104 "web@docker" "http://172.21.0.4:8000" 6ms
web                   | Not Found: /api/overview
me-project-traefik-1  | 78.24.102.87 - - [15/Jun/2022:10:21:47 +0000] "GET /api/overview HTTP/2.0" 404 179 "-" "-" 105 "web@docker" "http://172.21.0.4:8000" 2ms
web                   | Not Found: /api/overview
me-project-traefik-1  | 78.24.102.87 - - [15/Jun/2022:10:21:52 +0000] "GET /api/overview HTTP/2.0" 404 179 "-" "-" 106 "web@docker" "http://172.21.0.4:8000" 2ms
web                   | Not Found: /api/overview
me-project-traefik-1  | 78.24.102.87 - - [15/Jun/2022:10:21:57 +0000] "GET /api/overview HTTP/2.0" 404 179 "-" "-" 107 "web@docker" "http://172.21.0.4:8000" 2ms
web                   | Not Found: /api/overview
me-project-traefik-1  | 78.24.102.87 - - [15/Jun/2022:10:22:02 +0000] "GET /api/overview HTTP/2.0" 404 179 "-" "-" 108 "web@docker" "http://172.21.0.4:8000" 2ms
web                   | Not Found: /api/overview
me-project-traefik-1  | 78.24.102.87 - - [15/Jun/2022:10:22:07 +0000] "GET /api/overview HTTP/2.0" 404 179 "-" "-" 109 "web@docker" "http://172.21.0.4:8000" 3ms

docker-compose file:

version: '3.7'
services:
  web:
    container_name: web
    build:
      context: ./MoreEnergy
      dockerfile: Dockerfile.prod
    restart: always
    env_file: ./.env.prod
    entrypoint: sh ./entrypoint.sh
    command: gunicorn MoreEnergy.wsgi:application --bind 0.0.0.0:8000
    expose:
      - 8000
    volumes:
      - static_volume:/home/app/web/staticfiles
      - media_volume:/home/app/web/mediafiles
    depends_on:
      - db
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web.rule=Host(`my.site.com`)"
      - "traefik.http.routers.web.tls=true"
      - "traefik.http.routers.web.tls.certresolver=letsencrypt"
  db:
    container_name: dev_db
    image: postgres:12.0-alpine
    ports:
      - "5432:5432"
    env_file: ./.env.prod
    volumes:
      - postgres_data:/var/lib/postgresql/data/
  traefik:
    build:
      context: ./traefik
      dockerfile: Dockerfile.traefik
    ports:
      - 80:80
      - 443:443
      - 8080:8080
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./traefik-public-certificates:/certificates"
    command:
      - "--api=true"
      - "--api.dashboard=true"
      - "--providers.docker=true"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api.entrypoints=dashboard"
      - "traefik.http.routers.dashboard.rule=Host(`my.site.com`) && PathPrefix(`/dashboard`)"
      - "traefik.http.routers.dashboard.tls=true"
      - "traefik.http.routers.dashboard.tls.certresolver=letsencrypt"
      - "traefik.http.routers.dashboard.service=api@internal"
      - "traefik.http.routers.dashboard.middlewares=auth"
      - "traefik.http.middlewares.auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/"


volumes:
  postgres_data:
  static_volume:
  media_volume:

Probably, traefik tries to make his inner api requests and can't reach them. I have api in my project with "/api/" prefix. I guess, traefik has conflict with my api. Or not?

Real host name was replaced to my.site.com.

Upvotes: 4

Views: 1472

Answers (1)

Michael Heil
Michael Heil

Reputation: 18475

I guess, traefik has conflict with my api. Or not?

Yes, there is a conflict.

In your example the dashboard rule is set to

- "traefik.http.routers.dashboard.rule=Host(`my.site.com`) && PathPrefix(`/dashboard`)"

However, according to the documentation on Dashboard Router Rule, you need to make sure that:

As underlined in the documentation for the api.dashboard option, the router rule defined for Traefik must match the path prefixes /api and /dashboard.

Here is the conflict with your application. Looking at the comprehensive list of Traefik's API Endpoints you could work around that by providing the following dashboard rule:

- "traefik.http.routers.dashboard.rule="Host(`my-domain.com`) && (PathPrefix(`/debug`) ||PathPrefix(`/api/http`) || PathPrefix(`/api/tcp`) || PathPrefix(`/api/udp`) || PathPrefix(`/api/entrypoints`) || PathPrefix(`/api/overview`) || PathPrefix(`/api/rawdata`) || PathPrefix(`/api/version`) || PathPrefix(`/dashboard`))"

Just make sure, that it catches all relevant endpoints and it does not interfere with your custom application.

Upvotes: 4

Related Questions