Traefik.docker.network = doesnt work. It's always random

Hello guys.
I upgraded my docker-compose.yml. But now I have a problem.
Since 3 months, I'm trying to figuring out why it's working 50% of the time. Each time I restart my docker-compose.yml, it can work, or it can't work.
I think I found it. the network is randomly chosen. I saw it with Authentik.
I tried to replicate the problem and here is the problem:

If I have multiple networks.

networks:
    socket_proxy: # /var/run/docker.sock
        ipam:
            config:
                - subnet: "192.168.50.0/24"
    backend:
        ipam:
            config:
                - subnet: "192.168.60.0/24"
    dmz: # proxy between backend / frontend
        ipam:
            config:
                - subnet: "192.168.70.0/24"
    frontend:
        ipam:
            config:
                - subnet: "192.168.80.0/24"

And I use traefik with a service, like nginx:

services:
    traefik:
        networks:
            - socket_proxy
            - frontend

    nginx:
        ...
        networks:
            - frontend
            - dmz
        labels:
            - "traefik.enable=true"
            - "traefik.docker.network=frontend"
            ## HTTPS Routers
            - "traefik.http.routers.nginx-secure-rtr.entrypoints=websecure"
            - "traefik.http.routers.nginx-secure-rtr.rule=Host(`nginx.mydomain.com`)"
            - "traefik.http.routers.nginx-secure-rtr.tls=true"
            ## HTTPS Services
            - "traefik.http.routers.nginx-secure-rtr.service=nginx-svc"
            - "traefik.http.services.nginx-svc.loadbalancer.server.port=80"
            ## MIDDLEWARES
      #      - "traefik.http.routers.nginx-secure-rtr.middlewares=chain-multi-auth@file"
            - "traefik.http.routers.nginx-secure-rtr.middlewares=chain-authentik@file"

Traefik gonna take randomly "dmz" or "frontend" as network.
Even when "traefik.docker.network=frontend" is there.

  • 192.168.70.X ==> bad
  • 192.168.80.X ==> good

What can it be? Is it in the static file?
Thank for your help.

Bad gateway usually happens when Traefik and target service are not connected to the same or multiple Docker networks.

It’s probably about:

 - "traefik.docker.network=frontend"

You can try one of those:

  • adapt it to the real Docker network name (which gets a prefix by compose, use docker networks ls to check
  • probably better to add name: frontend to the compose network definition (to keep the name fixed)

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