Wrong IP used for service

Hi,

I have setup Traefik and can access the whoami sample container. I have another stack of containers that use their "default" network to communicate among each other. For the nginx container I defined the "traefik" network as a second network.
When I try to access that service now, I get gateway timeout error. In the debug log, I see that traefik is trying to reach nginx via the IP of the default network and not via the IP of the traefik network. This is the config of the stack, the nginx_recipes service is the one that I try to reach via traefic:

networks:
    default:
    traefik:
       external:
         name: traefik
         
services:
  db_recipes:
    image: postgres:15
    restart: always
    volumes:
      - /home/reiner/recipes_postgresql:/var/lib/postgresql/data
    env_file:
      - stack.env
    user: '1000:1000'
    networks:
      - default
      
  web_recipes:
    image: vabene1111/recipes
    restart: always
    volumes:
      - /home/reiner/recipes_staticfiles:/opt/recipes/staticfiles
      - /home/reiner/recipes_nginx_config:/opt/recipes/nginx/conf.d
      - /home/reiner/recipes_mediafiles:/opt/recipes/mediafiles
    env_file:
      - stack.env
    depends_on:
      - db_recipes
    networks:
      - default

  nginx_recipes:
    image: nginx:mainline-alpine
    restart: always
    volumes:
      - /home/reiner/recipes_nginx_config:/etc/nginx/conf.d:ro
      - /home/reiner/recipes_staticfiles:/static
      - /home/reiner/recipes_mediafiles:/media
    env_file:
      - stack.env
    depends_on:
      - web_recipes
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.recipes.rule=Host(`recipes.localnet.local`)"
      - "traefik.http.routers.recipes.entrypoints=http"
    networks:
      - default
      - traefik

How can I configure traefik to use the IP on the traefik network?

When using various Docker networks, define docker.network globally on providers.docker or individually on labels.

Many thanks! That was the part that was missing.

I added the label "traefik.docker.network=traefik" to the nginx_recipes service and now it works.

To fix the issue, just add this label to your nginx_recipes service: traefik.docker.network=traefik. This tells Traefik to use the IP from the traefik network instead of the default one. It’s a common hiccup when services are on multiple networks—Traefik just needs a little guidance on which one to use.