# Docker provider: how does Traefik choose which service IP address to proxy to when container is on multiple networks?

**URL:** <https://community.traefik.io/t/docker-provider-how-does-traefik-choose-which-service-ip-address-to-proxy-to-when-container-is-on-multiple-networks/16852>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [December 17, 2022, 8:44pm UTC](https://community.traefik.io/t/docker-provider-how-does-traefik-choose-which-service-ip-address-to-proxy-to-when-container-is-on-multiple-networks/16852 "2022-12-17T20:44:39Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![candlerb](https://avatars.discourse-cdn.com/v4/letter/c/c5a1d2/32.png) [@candlerb](https://community.traefik.io/u/candlerb)\
**Post date:** [December 18, 2022, 9:31am UTC](https://community.traefik.io/t/docker-provider-how-does-traefik-choose-which-service-ip-address-to-proxy-to-when-container-is-on-multiple-networks/16852/2 "2022-12-18T09:31:51Z")

</div>

I think I have found the solution. I looked through the [source code](https://github.com/traefik/traefik/blob/v2.9.6/pkg/provider/docker/config.go#L276-L373) and found a couple of relevant configuration options:

- `UseBindPortIP`
- `ExtraConf.Docker.Network`

The latter is documented [here](https://doc.traefik.io/traefik/providers/docker/#network) as configuration setting "providers.docker.network" or label "traefik.docker.network".

If I select the network explicitly:

```auto
# Docker configuration backend
providers:
  docker:
    defaultRule: "Host(`{{ trimPrefix `/` .Name }}.docker.localhost`)"
    exposedByDefault: false
    network: traefik_proxy # <<<<<

```

it appears to work fine - yay!!

That just leaves my original question: how does traefik choose by default? And I think the answer is [here](https://github.com/traefik/traefik/blob/v2.9.6/pkg/provider/docker/config.go#L367-L369):

```go
	for _, network := range container.NetworkSettings.Networks {
		return network.Addr
	}

```

Since networkSettings.Networks is a [map](https://github.com/traefik/traefik/blob/v2.9.6/pkg/provider/docker/docker.go#L103), and Go randomizes map iteration, it literally picks one interface address _at random_.

That was quite hard work to solve though, especially because the randomness causes an intermittent problem. Perhaps this behaviour could be made clearer in the documentation?

Regards,

Brian.

---

_[View the full topic](https://community.traefik.io/t/docker-provider-how-does-traefik-choose-which-service-ip-address-to-proxy-to-when-container-is-on-multiple-networks/16852)._
