Problem using a middleware cross providers

Hi,

I'm using docker as provider and starting traefik as container. In the docker-compose file I'm refferencing the "auth" middleware with @file. But I'm getting an error message about not finding the middleware from the file:

level=error msg="middleware \"auth@file\" does not exist" routerName=traefik@docker entryPointName=web-secure

My traefik.yml:

entryPoints:
  web:
    address: ":80"

  web-secure:
    address: ":443"

http:
  middlewares:
    http-redirectscheme:
      redirectScheme:
        scheme: https
    auth:
      basicAuth:
        users:
          - "xxxxxxxx"

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedbydefault: false

api:
  insecure: true
  dashboard: true

certificatesResolvers: 
  myhttpchallenge:
    acme:
      httpChallenge:
        entryPoint: web
      email: "xxxxxxxxx"
      storage: "acme.json"

My docker-compose.yml:

version: '3.4'

services:
  traefik:
    image: traefik:2.0
    command: --api.insecure=true --providers.docker 
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /home/root/docker/traefik2/traefik.yml:/traefik.yml
      - /home/root/docker/traefik2/acme.json:/acme.json
    container_name: traefik2
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.rule=Host(`xxxxxxxx`)"
      - "traefik.http.routers.traefik.entrypoints=web-secure"
      - "traefik.http.routers.traefik.tls.certresolver=myhttpchallenge"
      - "traefik.http.routers.traefik.service=api@internal"
      - "traefik.http.routers.traefik.middlewares=auth@file"

Thanks for help!

hello,

in the v2 the static and the dynamic configuration must define in 2 files.

dynamic configuration:

static configuration:

# traefik.yml
# static configuration

entryPoints:
  web:
    address: ":80"

  web-secure:
    address: ":443"

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedbydefault: false
  file:
    filename: /dynamic.yml

api:
  insecure: true

certificatesResolvers:
  myhttpchallenge:
    acme:
      email: "xxxxxxxxx"
      storage: "acme.json"
      httpChallenge:
        entryPoint: web
# dynamic.yml
# dynamic configuration

http:
  middlewares:
    http-redirectscheme:
      redirectScheme:
        scheme: https
    auth:
      basicAuth:
        users:
          - "xxxxxxxx"
version: '3.4'

services:
  traefik:
    image: traefik:2.0
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /home/root/docker/traefik2/traefik.yml:/traefik.yml
      - /home/root/docker/traefik2/dynamic.yml:/dynamic.yml
      - /home/root/docker/traefik2/acme.json:/acme.json
    container_name: traefik2
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.rule=Host(`xxxxxxxx`)"
      - "traefik.http.routers.traefik.entrypoints=web-secure"
      - "traefik.http.routers.traefik.tls.certresolver=myhttpchallenge"
      - "traefik.http.routers.traefik.service=api@internal"
      - "traefik.http.routers.traefik.middlewares=auth@file"

Also you cannot use CLI and file at the same time for the static configuration:

There are three different, mutually exclusive (e.g. you can use only one at the same time), ways to define static configuration options in Traefik

Thank you very much for the quick response!