# Specifying docker network multiple times

**URL:** <https://community.traefik.io/t/specifying-docker-network-multiple-times/18900>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [June 9, 2023, 4:04am UTC](https://community.traefik.io/t/specifying-docker-network-multiple-times/18900 "2023-06-09T04:04:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lonix](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lonix/32/7172_2.png) [@lonix](https://community.traefik.io/u/lonix)\
**Post date:** [June 9, 2023, 4:04am UTC](https://community.traefik.io/t/specifying-docker-network-multiple-times/18900/1 "2023-06-09T04:04:30Z")

</div>

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`:

```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?

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [June 9, 2023, 12:37pm UTC](https://community.traefik.io/t/specifying-docker-network-multiple-times/18900/2 "2023-06-09T12:37:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lonix](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lonix/32/7172_2.png) [@lonix](https://community.traefik.io/u/lonix)\
**Post date:** [June 9, 2023, 12:44pm UTC](https://community.traefik.io/t/specifying-docker-network-multiple-times/18900/3 "2023-06-09T12:44:03Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [June 9, 2023, 12:50pm UTC](https://community.traefik.io/t/specifying-docker-network-multiple-times/18900/4 "2023-06-09T12:50:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [June 12, 2023, 12:59pm UTC](https://community.traefik.io/t/specifying-docker-network-multiple-times/18900/6 "2023-06-12T12:59:01Z")

</div>

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