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

default route for container in multiple user defined networks #20179

Open
thechile opened this Issue Feb 10, 2016 · 11 comments

Comments

Projects
None yet
8 participants
@thechile
Copy link

thechile commented Feb 10, 2016

At the moment if you connect a container to multiple user defined networks then the default route used will be the subnet of the last connected network. Is there any way to avoid the order which the container is added to the networks determining which default route is used ? Something like docker network connect backend rose --no-default-route

In the below example, a way to avoid adding the backend network to the container and it automatically becoming the default gw. It would be nice to have the behavior user definable.

docker network create frontend
docker network create backend
docker run -d --name rose --net=frontend busybox top
docker exec rose ip r

default via 172.20.0.1 dev eth0 
172.20.0.0/16 dev eth0  src 172.20.0.2

docker network connect backend rose
docker exec rose ip r

default via 172.21.0.1 dev eth1 
172.20.0.0/16 dev eth0  src 172.20.0.2 
172.21.0.0/16 dev eth1  src 172.21.0.2 
@aboch

This comment has been minimized.

Copy link
Contributor

aboch commented Feb 10, 2016

As you said, the option is currently missing in the UI, but this can be done.

In fact libnetwork code already provides a way to set the priority of the endpoint, so that in case of container connected to multiple networks, the container's default gateway is determined by the highest priority endpoint.

@thechile

This comment has been minimized.

Copy link

thechile commented Feb 10, 2016

ok thanks for confirming. Being able to specify a priority to control which user defined network associated with a container is chosen for default gw would be useful.

Hopefully this will be plumbed in soon.

@irsl

This comment has been minimized.

Copy link

irsl commented Feb 13, 2016

+1 (similar request here: #20067)

@GordonTheTurtle

This comment has been minimized.

Copy link

GordonTheTurtle commented Feb 19, 2016

USER POLL

The best way to get notified of updates is to use the Subscribe button on this page.

Please don't use "+1" or "I have this too" comments on issues. We automatically
collect those comments to keep the thread short.

The people listed below have upvoted this issue by leaving a +1 comment:

@JrCs

@aboch

This comment has been minimized.

Copy link
Contributor

aboch commented Feb 22, 2016

Regarding #20179 (comment), I forgot to mention: Any help is appreciated in adding the missing code.

@LK4D4

This comment has been minimized.

Copy link
Contributor

LK4D4 commented Sep 14, 2016

@aboch is this still an issue? Do you think #20067 is duplicate?

@aboch

This comment has been minimized.

Copy link
Contributor

aboch commented Sep 14, 2016

@LK4D4 I think the two issues are not a duplicate. This one is about controlling the default route the other one is about a consistent interface order.

@thechile
Regarding

At the moment if you connect a container to multiple user defined networks then the default route used will be the subnet of the last connected network.

that is not the generic rule, the pickup logic is now clarified in the docs https://github.com/docker/docker/blob/master/docs/userguide/networking/index.md:

When a container is connected to multiple networks, its external connectivity is provided via the first non-internal network, in lexical order.

So even now if you play with the network names, you can deterministally impose the default route to choose.

@tarunlalwani

This comment has been minimized.

Copy link

tarunlalwani commented Oct 1, 2017

Any update on this? What is the way to choose the default gateway in case of multiple networks?

@moby moby deleted a comment from horihel Oct 1, 2017

@moby moby deleted a comment from sanmai-NL Oct 1, 2017

@moby moby deleted a comment from horihel Oct 1, 2017

@thaJeztah

This comment has been minimized.

Copy link
Member

thaJeztah commented Oct 1, 2017

removed the "out of office" messages 👍

@moby moby deleted a comment from horihel Oct 2, 2017

@logicethos

This comment has been minimized.

Copy link

logicethos commented Nov 3, 2017

I know it's been discussed before, but having --net=[ ] seems the logical way to do this. The first network in the list, becomes the default.

I just ran into this myself. Rebooted my server, and when the container came back up, eth0 and eth1 flipped causing the service inside the container to fail.

@thaJeztah

This comment has been minimized.

Copy link
Member

thaJeztah commented Nov 3, 2017

@logicethos unfortunately, that won't resolve situations where you docker network connect or docker network disconnect networks.

Note that multiple --net / --network flags is not supported yet, but I opened a proposal to bring in the foundations for allowing this; see #31964, and the "related issues" section in that proposal.

The advanced syntax has been implemented for services, but not yet for docker run (see docker/cli#317)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment