Gateway timeout on one of the services/containers

I have the following docker-compose setup. I have two nginx containers that are connected with
traefik. The one labeled with foobar.test works, the one labeled with foobar.test && pathPrefix /admin doesn't work most of the time. Sometimes it works, but most of the time after bringing the containers down and back up it doesn't work anymore.

version: '3.7'

services:
  traefik:
    image: traefik:v2.0
    command: --api.insecure=true --providers.docker --providers.docker.exposedByDefault=false
    ports:
      - '80:80'
      - '8080:8080'
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - proxy

  mysql:
    container_name: mysql
    image: mysql:8.0.19
    command: --default-authentication-plugin=mysql_native_password
    environment:
      - MYSQL_ROOT_PASSWORD=$DB_PASSWORD
    ports:
      - 3306:3306
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - mysql

  client:
    image: nginx:1.17.10-alpine
    volumes:
      - ./client/public:/usr/share/nginx/html
    labels:
      - traefik.http.routers.foobar_client.rule=Host(`foobar.test`)
      - traefik.enable=true
    networks:
      - proxy

  admin_nginx:
    build:
      context: ./admin
      dockerfile: ./docker/nginx/Dockerfile.dev
    volumes:
      - ./admin/public:/app/public
    networks:
      - proxy
      - admin
    labels:
      - traefik.http.routers.foobar_admin.rule=Host(`foobar.test`) && PathPrefix(`/admin`)
      - traefik.enable=true

  admin_php-fpm:
    container_name: php-fpm
    build:
      context: ./admin
      dockerfile: ./docker/php-fpm/Dockerfile.dev
    volumes:
      - ./admin:/app
    networks:
      - admin
      - mysql

networks:
  proxy:
    name: proxy
    driver: bridge
  mysql:
    name: mysql
    driver: bridge
  admin:
    name: admin
    driver: bridge

volumes:
  mysql_data:
    name: mysql_data

Any ideas what I'm doing wrong? Thnx in advance!

One other thing, if I add the admin network to the traefik container everything works. But that is rather strange because they (traefik and admin_nginx) already share the network called proxy.

As the container has two networks, you need to tell traefik which network to use. It is currently flipping between the two and only one works.

- traefik.docker.network=proxy

Thank you very much! That was it. In hindsight pretty logical, but I didn't knew that could happen.

Found out the hard way myself.

I kind of think that Traefik should be able to match networks. Actually TraefikEE supports this and will connect the Proxy to the correct network, so might just be a pay to play only feature.