Error to proxy service when it have multiple docker networks

GitHub Issue: #6597

Do you want to request a feature or report a bug?

Bug

What did you do?

I setup two network a docker compose with two networks: frontend and backend.
I configure traefik to use only the frontend one.
In docker-compose there are other 2 container: ldap with backend network and phpldapadmin with frontend and backend network.

What did you expect to see?

I expected that traefik should use the frontend network to proxy on phpldapadmin container.

What did you see instead?

When I check traefik logs, I found that traefik use backend network to proxy on phpldapadmin.

Output of traefik version: (What version of Traefik are you using?)

Version:      2.2.0
Codename:     chevrotin
Go version:   go1.14.1
Built:        2020-03-25T17:32:57Z
OS/Arch:      linux/amd64

What is your environment & configuration (arguments, toml, provider, platform, ...)?

version: '2.3'

networks:
  backend:
  frontend:

volumes:
  varlibldap:
    driver: local
  etcldapslapdd:
    driver: local
  varwwwphpldapadmin:
    driver: local

services:

  traefik:
    image: traefik:2.2
    networks:
      frontend:
    ports:
      - "80:80"
      - "8080:8080"
      - "443:443"
    command:
      - "--api.insecure=true"
      - "--accesslog=true"
      - "--providers.docker.exposedByDefault=false"
      - "--entryPoints.http.address=:80"
      - "--entryPoints.https.address=:443"
      - "--log.level=DEBUG"
      - "--providers.docker"
      - "--providers.docker.network=frontend"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  ldap:
    image: osixia/openldap:1.3.0
    hostname: ldap.docker.local
    networks:
      backend:
    environment:
      LDAP_ORGANISATION: "ACME Inc."
      LDAP_DOMAIN: "corp.acme.com"
      LDAP_ADMIN_PASSWORD: "JonSn0w"
      LDAP_TLS: 'true'
    volumes:
      - varlibldap:/var/lib/ldap
      - etcldapslapdd:/etc/ldap/slapd.d

  phpldapadmin:
    image: osixia/phpldapadmin:0.9.0
    hostname: phpldapadmin.docker.local
    networks:
      frontend:
        aliases: 
          - phpldapadmin.docker.local
      backend:
    environment:
      PHPLDAPADMIN_LDAP_HOSTS: ldap
      PHPLDAPADMIN_HTTPS: 'false'
    volumes:
      - varwwwphpldapadmin:/var/www/phpldapadmin
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=frontend"
      # http entrypoint
      - "traefik.http.middlewares.phpldapadmin-http2https.redirectscheme.permanent=true"
      - "traefik.http.middlewares.phpldapadmin-http2https.redirectscheme.scheme=https"
      - "traefik.http.routers.phpldapadmin-http.entryPoints=http"
      - "traefik.http.routers.phpldapadmin-http.rule=Host(`phpldapadmin.docker.local`)"
      - "traefik.http.routers.phpldapadmin-http.middlewares=phpldapadmin-http2https"
      # https entrypoint
      - "traefik.http.routers.phpldapadmin-https.entryPoints=https"
      - "traefik.http.routers.phpldapadmin-https.rule=Host(`phpldapadmin.docker.local`)"
      - "traefik.http.routers.phpldapadmin-https.service=phpldapadmin-https"
      - "traefik.http.routers.phpldapadmin-https.tls=true"
      - "traefik.http.services.phpldapadmin-https.loadbalancer.passhostheader=true"
      - "traefik.http.services.phpldapadmin-https.loadbalancer.server.port=80"
      - "traefik.http.services.phpldapadmin-https.loadbalancer.server.scheme=http"
[
    {
        "Name": "ldap_frontend",
        "Id": "73289f098e5882002457f21ff26375949c3836bc2d49ac8c9dbe21ee0c86d572",
        "Created": "2020-03-28T13:16:11.544039756Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.22.0.0/16",
                    "Gateway": "172.22.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "6a0846f7819a64861f57ef3f7826c63d29ef6706f4625fa0607778c9631ee6cd": {
                "Name": "ldap_traefik_1",
                "EndpointID": "19d6275a28c73e86d745e203fad6b61ecb557ddea4f78942b5165182949743a2",
                "MacAddress": "02:42:ac:16:00:02",
                "IPv4Address": "172.22.0.2/16",
                "IPv6Address": ""
            },
            "afc33c57d8c24bce96baa053e15db22678955da81c3d36896e89933c34102505": {
                "Name": "ldap_phpldapadmin_1",
                "EndpointID": "16873d06f5c337a26b4b79bb18f2f8315f7b8a9400f1a6a4e24cec054c9d1440",
                "MacAddress": "02:42:ac:16:00:03",
                "IPv4Address": "172.22.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "frontend",
            "com.docker.compose.project": "ldap",
            "com.docker.compose.version": "1.25.4"
        }
    }
]
[
    {
        "Name": "ldap_backend",
        "Id": "a2a085ba6dbed90cbb5a1a96645c8350a289257f64cf095255b894740683dbe2",
        "Created": "2020-03-28T13:16:11.582686779Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.23.0.0/16",
                    "Gateway": "172.23.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "afc33c57d8c24bce96baa053e15db22678955da81c3d36896e89933c34102505": {
                "Name": "ldap_phpldapadmin_1",
                "EndpointID": "000567e6184c3127019baded7330a7fb3d08997f5a467941e0732f7354bbed14",
                "MacAddress": "02:42:ac:17:00:03",
                "IPv4Address": "172.23.0.3/16",
                "IPv6Address": ""
            },
            "c8e8f9ac64d442c395d080d8484f741c98c253125d465d0abd1fd003a0b76b46": {
                "Name": "ldap_ldap_1",
                "EndpointID": "e62ee891d796f2d866c899112e63b7185d5065d431999ebe6fc54b472ff75e68",
                "MacAddress": "02:42:ac:17:00:02",
                "IPv4Address": "172.23.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "backend",
            "com.docker.compose.project": "ldap",
            "com.docker.compose.version": "1.25.4"
        }
    }
]

If applicable, please paste the log output in DEBUG level (--log.level=DEBUG switch)

❯ docker-compose logs -f traefik
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Configuration received from provider docker: {\"http\":{\"routers\":{\"phpldapadmin-http\":{\"entryPoints\":[\"http\"],\"middlewares\":[\"phpldapadmin-http2https\"],\"service\":\"phpldapadmin-https\",\"rule\":\"Host(`phpldapadmin.docker.local`)\"},\"phpldapadmin-https\":{\"entryPoints\":[\"https\"],\"service\":\"phpldapadmin-https\",\"rule\":\"Host(`phpldapadmin.docker.local`)\",\"tls\":{}}},\"services\":{\"phpldapadmin-https\":{\"loadBalancer\":{\"servers\":[{\"url\":\"http://172.23.0.3:80\"}],\"passHostHeader\":true}}},\"middlewares\":{\"phpldapadmin-http2https\":{\"redirectScheme\":{\"scheme\":\"https\",\"permanent\":true}}}},\"tcp\":{},\"udp\":{}}" providerName=docker
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Creating middleware" routerName=phpldapadmin-http@docker serviceName=phpldapadmin-https entryPointName=http middlewareName=pipelining middlewareType=Pipelining
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Creating load-balancer" entryPointName=http routerName=phpldapadmin-http@docker serviceName=phpldapadmin-https
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Creating server 0 http://172.23.0.3:80" serviceName=phpldapadmin-https serverName=0 entryPointName=http routerName=phpldapadmin-http@docker
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Added outgoing tracing middleware phpldapadmin-https" routerName=phpldapadmin-http@docker entryPointName=http middlewareName=tracing middlewareType=TracingForwarder
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Creating middleware" entryPointName=http routerName=phpldapadmin-http@docker middlewareName=phpldapadmin-http2https@docker middlewareType=RedirectScheme
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Setting up redirection to https " entryPointName=http routerName=phpldapadmin-http@docker middlewareName=phpldapadmin-http2https@docker middlewareType=RedirectScheme
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Adding tracing to middleware" routerName=phpldapadmin-http@docker entryPointName=http middlewareName=phpldapadmin-http2https@docker
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Creating middleware" entryPointName=http middlewareName=traefik-internal-recovery middlewareType=Recovery
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Added outgoing tracing middleware api@internal" entryPointName=traefik routerName=api@internal middlewareName=tracing middlewareType=TracingForwarder
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Added outgoing tracing middleware dashboard@internal" middlewareType=TracingForwarder entryPointName=traefik routerName=dashboard@internal middlewareName=tracing
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Creating middleware" entryPointName=traefik routerName=dashboard@internal middlewareName=dashboard_stripprefix@internal middlewareType=StripPrefix
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Adding tracing to middleware" middlewareName=dashboard_stripprefix@internal entryPointName=traefik routerName=dashboard@internal
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Creating middleware" entryPointName=traefik routerName=dashboard@internal middlewareName=dashboard_redirect@internal middlewareType=RedirectRegex
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Setting up redirection from ^(http:\\/\\/[^:\\/]+(:\\d+)?)\\/$ to ${1}/dashboard/" middlewareName=dashboard_redirect@internal middlewareType=RedirectRegex entryPointName=traefik routerName=dashboard@internal
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Adding tracing to middleware" middlewareName=dashboard_redirect@internal entryPointName=traefik routerName=dashboard@internal
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Creating middleware" middlewareType=Recovery entryPointName=traefik middlewareName=traefik-internal-recovery
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Creating middleware" middlewareType=Pipelining serviceName=phpldapadmin-https entryPointName=https routerName=phpldapadmin-https@docker middlewareName=pipelining
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Creating load-balancer" entryPointName=https routerName=phpldapadmin-https@docker serviceName=phpldapadmin-https
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Creating server 0 http://172.23.0.3:80" routerName=phpldapadmin-https@docker serviceName=phpldapadmin-https entryPointName=https serverName=0
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Added outgoing tracing middleware phpldapadmin-https" routerName=phpldapadmin-https@docker middlewareName=tracing middlewareType=TracingForwarder entryPointName=https
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="Creating middleware" entryPointName=https middlewareName=traefik-internal-recovery middlewareType=Recovery
traefik_1       | time="2020-03-28T13:16:12Z" level=debug msg="No default certificate, generating one"
traefik_1       | time="2020-03-28T13:16:13Z" level=debug msg="Serving default certificate for request: \"phpldapadmin.docker.local\""
traefik_1       | time="2020-03-28T13:16:13Z" level=debug msg="http: TLS handshake error from 172.22.0.1:45002: remote error: tls: unknown certificate"
traefik_1       | time="2020-03-28T13:16:16Z" level=debug msg="Serving default certificate for request: \"phpldapadmin.docker.local\""
traefik_1       | time="2020-03-28T13:16:16Z" level=debug msg="http: TLS handshake error from 172.22.0.1:45006: remote error: tls: unknown certificate"
traefik_1       | time="2020-03-28T13:16:23Z" level=debug msg="Serving default certificate for request: \"phpldapadmin.docker.local\""
traefik_1       | time="2020-03-28T13:16:23Z" level=debug msg="http: TLS handshake error from 172.22.0.1:45010: remote error: tls: unknown certificate"
traefik_1       | time="2020-03-28T13:16:23Z" level=debug msg="Serving default certificate for request: \"phpldapadmin.docker.local\""
traefik_1       | time="2020-03-28T13:16:23Z" level=debug msg="vulcand/oxy/roundrobin/rr: begin ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7\"],\"Cache-Control\":[\"max-age=0\"],\"Cookie\":[\"5d89dac18813e15aa2f75788275e3588=hcpnhqnbu2lu8f7daauqb6ejfm; collapsedNodes=\"],\"Sec-Fetch-Dest\":[\"document\"],\"Sec-Fetch-Mode\":[\"navigate\"],\"Sec-Fetch-Site\":[\"none\"],\"Sec-Fetch-User\":[\"?1\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36\"],\"X-Forwarded-Host\":[\"phpldapadmin.docker.local\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"6a0846f7819a\"],\"X-Real-Ip\":[\"172.22.0.1\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"phpldapadmin.docker.local\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.22.0.1:45014\",\"RequestURI\":\"/\",\"TLS\":null}"
traefik_1       | time="2020-03-28T13:16:23Z" level=debug msg="vulcand/oxy/roundrobin/rr: Forwarding this request to URL" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7\"],\"Cache-Control\":[\"max-age=0\"],\"Cookie\":[\"5d89dac18813e15aa2f75788275e3588=hcpnhqnbu2lu8f7daauqb6ejfm; collapsedNodes=\"],\"Sec-Fetch-Dest\":[\"document\"],\"Sec-Fetch-Mode\":[\"navigate\"],\"Sec-Fetch-Site\":[\"none\"],\"Sec-Fetch-User\":[\"?1\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36\"],\"X-Forwarded-Host\":[\"phpldapadmin.docker.local\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"6a0846f7819a\"],\"X-Real-Ip\":[\"172.22.0.1\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"phpldapadmin.docker.local\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.22.0.1:45014\",\"RequestURI\":\"/\",\"TLS\":null}" ForwardURL="http://172.23.0.3:80"
traefik_1       | time="2020-03-28T13:16:24Z" level=debug msg="'499 Client Closed Request' caused by: context canceled"
traefik_1       | time="2020-03-28T13:16:24Z" level=debug msg="vulcand/oxy/roundrobin/rr: completed ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7\"],\"Cache-Control\":[\"max-age=0\"],\"Cookie\":[\"5d89dac18813e15aa2f75788275e3588=hcpnhqnbu2lu8f7daauqb6ejfm; collapsedNodes=\"],\"Sec-Fetch-Dest\":[\"document\"],\"Sec-Fetch-Mode\":[\"navigate\"],\"Sec-Fetch-Site\":[\"none\"],\"Sec-Fetch-User\":[\"?1\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36\"],\"X-Forwarded-Host\":[\"phpldapadmin.docker.local\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"6a0846f7819a\"],\"X-Real-Ip\":[\"172.22.0.1\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"phpldapadmin.docker.local\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.22.0.1:45014\",\"RequestURI\":\"/\",\"TLS\":null}"
traefik_1       | 172.22.0.1 - - [28/Mar/2020:13:16:23 +0000] "GET / HTTP/2.0" 499 21 "-" "-" 1 "phpldapadmin-https@docker" "http://172.23.0.3:80" 1039ms
traefik_1       | time="2020-03-28T13:16:24Z" level=debug msg="vulcand/oxy/roundrobin/rr: begin ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7\"],\"Cache-Control\":[\"max-age=0\"],\"Cookie\":[\"5d89dac18813e15aa2f75788275e3588=hcpnhqnbu2lu8f7daauqb6ejfm; collapsedNodes=\"],\"Sec-Fetch-Dest\":[\"document\"],\"Sec-Fetch-Mode\":[\"navigate\"],\"Sec-Fetch-Site\":[\"cross-site\"],\"Sec-Fetch-User\":[\"?1\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36\"],\"X-Forwarded-Host\":[\"phpldapadmin.docker.local\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"6a0846f7819a\"],\"X-Real-Ip\":[\"172.22.0.1\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"phpldapadmin.docker.local\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.22.0.1:45014\",\"RequestURI\":\"/\",\"TLS\":null}"
traefik_1       | time="2020-03-28T13:16:24Z" level=debug msg="vulcand/oxy/roundrobin/rr: Forwarding this request to URL" ForwardURL="http://172.23.0.3:80" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7\"],\"Cache-Control\":[\"max-age=0\"],\"Cookie\":[\"5d89dac18813e15aa2f75788275e3588=hcpnhqnbu2lu8f7daauqb6ejfm; collapsedNodes=\"],\"Sec-Fetch-Dest\":[\"document\"],\"Sec-Fetch-Mode\":[\"navigate\"],\"Sec-Fetch-Site\":[\"cross-site\"],\"Sec-Fetch-User\":[\"?1\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36\"],\"X-Forwarded-Host\":[\"phpldapadmin.docker.local\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"6a0846f7819a\"],\"X-Real-Ip\":[\"172.22.0.1\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"phpldapadmin.docker.local\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.22.0.1:45014\",\"RequestURI\":\"/\",\"TLS\":null}"
traefik_1       | time="2020-03-28T13:16:54Z" level=debug msg="'504 Gateway Timeout' caused by: dial tcp 172.23.0.3:80: i/o timeout"
traefik_1       | time="2020-03-28T13:16:54Z" level=debug msg="vulcand/oxy/roundrobin/rr: completed ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7\"],\"Cache-Control\":[\"max-age=0\"],\"Cookie\":[\"5d89dac18813e15aa2f75788275e3588=hcpnhqnbu2lu8f7daauqb6ejfm; collapsedNodes=\"],\"Sec-Fetch-Dest\":[\"document\"],\"Sec-Fetch-Mode\":[\"navigate\"],\"Sec-Fetch-Site\":[\"cross-site\"],\"Sec-Fetch-User\":[\"?1\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36\"],\"X-Forwarded-Host\":[\"phpldapadmin.docker.local\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"6a0846f7819a\"],\"X-Real-Ip\":[\"172.22.0.1\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"phpldapadmin.docker.local\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.22.0.1:45014\",\"RequestURI\":\"/\",\"TLS\":null}"
traefik_1       | 172.22.0.1 - - [28/Mar/2020:13:16:24 +0000] "GET / HTTP/2.0" 504 15 "-" "-" 2 "phpldapadmin-https@docker" "http://172.23.0.3:80" 30001ms
traefik_1       | time="2020-03-28T13:16:55Z" level=debug msg="vulcand/oxy/roundrobin/rr: begin ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/favicon.ico\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"image/webp,image/apng,image/*,*/*;q=0.8\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7\"],\"Cache-Control\":[\"no-cache\"],\"Cookie\":[\"5d89dac18813e15aa2f75788275e3588=hcpnhqnbu2lu8f7daauqb6ejfm; collapsedNodes=\"],\"Pragma\":[\"no-cache\"],\"Referer\":[\"https://phpldapadmin.docker.local/\"],\"Sec-Fetch-Dest\":[\"image\"],\"Sec-Fetch-Mode\":[\"no-cors\"],\"Sec-Fetch-Site\":[\"same-origin\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36\"],\"X-Forwarded-Host\":[\"phpldapadmin.docker.local\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"6a0846f7819a\"],\"X-Real-Ip\":[\"172.22.0.1\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"phpldapadmin.docker.local\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.22.0.1:45014\",\"RequestURI\":\"/favicon.ico\",\"TLS\":null}"
traefik_1       | time="2020-03-28T13:16:55Z" level=debug msg="vulcand/oxy/roundrobin/rr: Forwarding this request to URL" ForwardURL="http://172.23.0.3:80" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/favicon.ico\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"image/webp,image/apng,image/*,*/*;q=0.8\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7\"],\"Cache-Control\":[\"no-cache\"],\"Cookie\":[\"5d89dac18813e15aa2f75788275e3588=hcpnhqnbu2lu8f7daauqb6ejfm; collapsedNodes=\"],\"Pragma\":[\"no-cache\"],\"Referer\":[\"https://phpldapadmin.docker.local/\"],\"Sec-Fetch-Dest\":[\"image\"],\"Sec-Fetch-Mode\":[\"no-cors\"],\"Sec-Fetch-Site\":[\"same-origin\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36\"],\"X-Forwarded-Host\":[\"phpldapadmin.docker.local\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"6a0846f7819a\"],\"X-Real-Ip\":[\"172.22.0.1\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"phpldapadmin.docker.local\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.22.0.1:45014\",\"RequestURI\":\"/favicon.ico\",\"TLS\":null}"
traefik_1       | time="2020-03-28T13:17:25Z" level=debug msg="'504 Gateway Timeout' caused by: dial tcp 172.23.0.3:80: i/o timeout"
traefik_1       | time="2020-03-28T13:17:25Z" level=debug msg="vulcand/oxy/roundrobin/rr: completed ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/favicon.ico\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"image/webp,image/apng,image/*,*/*;q=0.8\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7\"],\"Cache-Control\":[\"no-cache\"],\"Cookie\":[\"5d89dac18813e15aa2f75788275e3588=hcpnhqnbu2lu8f7daauqb6ejfm; collapsedNodes=\"],\"Pragma\":[\"no-cache\"],\"Referer\":[\"https://phpldapadmin.docker.local/\"],\"Sec-Fetch-Dest\":[\"image\"],\"Sec-Fetch-Mode\":[\"no-cors\"],\"Sec-Fetch-Site\":[\"same-origin\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36\"],\"X-Forwarded-Host\":[\"phpldapadmin.docker.local\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"6a0846f7819a\"],\"X-Real-Ip\":[\"172.22.0.1\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"phpldapadmin.docker.local\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.22.0.1:45014\",\"RequestURI\":\"/favicon.ico\",\"TLS\":null}"
traefik_1       | 172.22.0.1 - - [28/Mar/2020:13:16:55 +0000] "GET /favicon.ico HTTP/2.0" 504 15 "-" "-" 3 "phpldapadmin-https@docker" "http://172.23.0.3:80" 30001ms

Did you manage to resolve this?

It's pretty much the exact configuration I was trying to use. I see the gateway timeout because the router is trying to pass the traffic to the ip address of the container on the backend network.

Nevermind I found the solution with:

traefik.docker.network: frontend