Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Swarm Mode: traefik.docker.network should default only to networks that traefik is attached to #979

Closed
dfyx opened this issue Dec 19, 2016 · 5 comments

Comments

@dfyx
Copy link

dfyx commented Dec 19, 2016

Assume the following situation:

  • I'm using docker 1.12 in swarm mode
  • overlay network traefik-net with 192.168.0.0/24
  • overlay network backend with 192.168.1.0/24
  • the traefik container is only attached to the traefik-net network with the ip address 192.168.0.2
  • my application is attached to both networks because it needs to connect to a database container. Therefore it has two ip addresses: 192.168.0.4 and 192.168.1.2
  • the application has the following labels set: traefik.port=80 and traefik.frontend.rule=myapp.example.com

Expected behavior:
Traefik creates a backend for http://192.168.0.4

Observed behavior in 1.1.2:
Traefik alternates between http://192.168.0.4 and http://192.168.1.2 every time it refreshes its config which sporadically causes 502 Bad Gateway errors. This is clearly visible when refreshing the traefik web interface every 30 seconds or so.

Possible solutions/fixes:

  • My current workaround: explicitly set traefik.docker.network=traefik-net for every single application that is attached to more than one network
  • Simple solution: Allow setting a default value for traefik.docker.network in traefik.toml (as far as I can see from the docs this is not possible right now)
  • The "it just works" solution: only consider IP addresses that lie within networks that traefik is attached to
@dfyx
Copy link
Author

dfyx commented Dec 19, 2016

This is related to #959 and a followup to the closed #970

@michaelkrog
Copy link

I concur. I am exposed to this issue almost every time I create a new service that needs access to multiple networks.

I simply forget that extra label every time as it works perfectly fine without it for services that only binds to the same network as traefik does.

@centerorbit
Copy link

centerorbit commented Oct 3, 2017

I too have encountered this problem, but it exists with local docker-compose setup (no Swarm involved) as well.

I suspect the culprit is in getIPAddress of provider/docker/docker.go:

https://github.com/containous/traefik/blob/cf508b6d481599c4ffd83c52e48beb9cf561314a/provider/docker/docker.go#L611-L614

You'll notice that earlier in the function it attempts to pick a network based on things (such as the label). If no other option exists, it simply loops through all of the Containers possible networks, and picks the first one and returns it.

https://stackoverflow.com/a/46439598/663058

@nim65s
Copy link

nim65s commented Nov 16, 2018

Hi,
I think this should be closed by #3471

@mmatur
Copy link
Member

mmatur commented Nov 19, 2018

Closed by #3471.

Thanks @nim65s

@mmatur mmatur closed this as completed Nov 19, 2018
@mmatur mmatur added this to the 1.7 milestone Nov 19, 2018
@traefik traefik locked and limited conversation to collaborators Sep 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants