Specifying docker network multiple times

I've seen many traefik examples specifying the docker network, and then respecifying it in traefik's static/dynamic config as well as in service containers.

docker-compose.yml:

networks:
  traefik:
    name: traefik

services:

  traefik:
    image: traefik
    # ...
    networks:
      - traefik
    command:
     - --providers.docker.network=traefik         # <--- necessary?

  whoami:
    image: traefik/whoami
    # ...
    networks:
      - traefik
    labels:
      traefik.docker.network: traefik             # <--- necessary?

For me it works without those commented lines.

Are they necessary? Why do those settings exist?

This is relevant when your target service uses multiple networks that are not all shared with Traefik.

Traefik sees all IPs of the target service, but needs to know which of them can really be used.

1 Like

Thanks. That's an advanced scenario which probably doesn't apply to me. But out of curiosity, why not just add traefik to that docker network and avoid the problem?

Example:

  • Traefik uses proxy network
  • Kibana uses proxy and elastic network
  • Elasticsearch uses elastic network

As general security measure you don’t add more networks than necessary to a container.

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