Docker provider not working, returns error code 404

Have been trying to setup traefik as a reverse proxy with file and docker providers. Currently i have only gotten file provider to work. The docker provider only returns error code 404.

Test container setup:

docker run -d -p 3000:8080 --name webtest --network proxy --label traefik.enable=true rawmind/web-test

Traefik setup

docker run -d -p 8080:8080 -p 80:80 -p 443:443 --name traefik \
-v /srv/traefik/:/etc/traefik -v /var/run/docker.sock:/var/run/docker.sock \
 --env CLOUDFLARE_API_KEY=api-key \
 --env CLOUDFLARE_EMAIL=admin@domain.com \ traefik:2.7

traefik.yml

global:
  checkNewVersion: true
  sendAnonymousUsage: false

serversTransport:
  insecureSkipVerify: true

log:
  level: DEBUG

accesslog: {}

api:
  insecure: true
  dashboard: true

entryPoints:
  web:
    address: ":80"
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https 

  websecure:
    address: ":443"
    http:
      tls:
        # Generate a wildcard domain certificate
        certResolver: letsencrypt
        domains:
          - main: domain.com
            sans:
              - '*.domain.com'
      middlewares:
        - securityHeaders 

providers:
  providersThrottleDuration: 2s
  file:
    filename: /etc/traefik/fileConfig.yml
    watch: true

  docker:
    watch: true
    endpoint: "unix:///var/run/docker.sock"
    network: proxy
    defaultRule: "Host(`{{ lower (trimPrefix `/` .Name )}}.domain.com`)"
    exposedByDefault: false

# Use letsencrypt to generate ssl serficiates
certificatesResolvers:
  letsencrypt:
    acme:
      email: admin@domain.com
      storage: /etc/traefik/acme.json
      dnsChallenge:
        provider: cloudflare
        # Used to make sure the dns challenge is propagated to the rights dns servers
        resolvers:
          - "1.1.1.1:53"
          - "1.0.0.1:53"

fileConfig.yml

http:
  routers:
    test:
      entrypoints:
        - web
        - websecure
      rule: 'Host(`test.domain.com`)'
      service: test

  ## SERVICES ##
  services:
    test:
      loadBalancer:
        servers:
          - url: http://192.168.0.189:9453/

  ## MIDDLEWARES ##
  middlewares:
    # Only Allow Local networks
    whitelist:
      ipWhiteList:
        sourceRange: 
          - 127.0.0.1/32 # localhost
          - 192.168.0.0/24 # LAN Subnet
  
    # Security headers
    securityHeaders:
      headers:
        customResponseHeaders:
          X-Robots-Tag: "none,noarchive,nosnippet,notranslate,noimageindex"
          server: ""
          X-Forwarded-Proto: "https"
        sslProxyHeaders:
          X-Forwarded-Proto: https
        referrerPolicy: "strict-origin-when-cross-origin"
        hostsProxyHeaders:
          - "X-Forwarded-Host"
        customRequestHeaders:
          X-Forwarded-Proto: "https"
        contentTypeNosniff: true
        browserXssFilter: true
        forceSTSHeader: true
        stsIncludeSubdomains: true
        stsSeconds: 63072000
        stsPreload: true

Would you please explain what you mean by saying the Docker provider returns 404?

Once you configure the Docker provider, which you did in your example, the configuration is managed through labels.

I would also recommend starting working with Docker Compose, here is the example which is good for the beginning.

Hi

After I setup a container, I am getting 404 page not found, instead of being sent to correct webpage.
288429048_1083293885593490_1026711084654577035_n

The only thing in the access logs I can find is this:

192.168.0.90 - - [21/Jun/2022:12:06:05 +0000] "GET / HTTP/2.0" 404 19 "-" "-" 1184 "-" "-" 0ms

Is there any other labels you would need other than traefik.enable=true?
As for Docker Compose, the reason I am setting it up this way now, it that the plan is to configure it using Ansible.

Hello @KjetilKnutsen

Can you please share your docker-compose file? We will try to reproduce it on our test env.

I was perphaps not clear, I don't have any docker-compose file, because of wanting to set it up using Ansible later. The containers are only setup with the docker run commands previously given.

I understand. 404 means that Traefik is not finding the appropriate router to match your request criteria.

It might be caused by a configuration issue so validating your configuration should be crucial.

just wanted to ensure that we are on the same page,
Do we still investigate the issue with the Docker provider configuration?

Yes, it seems to be a configuration error as the test router works with file provider.
I still want to figure out what the problem is regarding the Docker provider configuration is.

After looking at it again today, I found the issues that were causing it to not work.

First was that the middleware on websecure was not properly set. It was missing @file

      middlewares:
        - securityHeaders@file

Second, was that I had forgot to add the correct docker network to the traefik container. Now it works as it should.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.