-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Comments
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. |
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. |
+1 (similar request here: #20067) |
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 The people listed below have upvoted this issue by leaving a +1 comment: |
Regarding #20179 (comment), I forgot to mention: Any help is appreciated in adding the missing code. |
@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
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:
So even now if you play with the network names, you can deterministally impose the default route to choose. |
Any update on this? What is the way to choose the default gateway in case of multiple networks? |
removed the "out of office" messages 👍 |
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. |
@logicethos unfortunately, that won't resolve situations where you Note that multiple The advanced syntax has been implemented for services, but not yet for |
In docker/compose/issues/4645, support was added for setting a It looks like there are still missing pieces according to @shin- : the priority parameter is still not passed to docker-py and therefore not to the docker engine.
self.client.connect_container_to_network(
container.id, network,
aliases=aliases,
ipv4_address=netdefs.get('ipv4_address', None),
ipv6_address=netdefs.get('ipv6_address', None),
links=self._get_links(False),
link_local_ips=netdefs.get('link_local_ips', None),
# priority=netdefs.get('priority', 0), # <= should be added
) It does look like libnetwork can, however, already accept a priority argument for ordering the container's interfaces as suggested by @aboch in comment#2:
func JoinOptionPriority(ep Endpoint, prio int) EndpointOption {
return func(ep *endpoint) {
// ep lock already acquired
c := ep.network.getController()
c.Lock()
sb, ok := c.sandboxes[ep.sandboxID]
c.Unlock()
if !ok {
logrus.Errorf("Could not set endpoint priority value during Join to endpoint %s: No sandbox id present in endpoint", ep.id)
return
}
sb.epPriority[ep.id] = prio
}
} There is a functional test in func TestSandboxAddMultiPrio(t *testing.T) {
... @thaJeztah: please can you confirm these two entities are related in their intended function? If so, is there value to create PRs spanning 3 components (compose, docker-py, moby) to link these parameters to achieve deterministic interface ordering in containers according to |
The priority would define only the order or as well the default gw. The interface with the highest prio will set the default gw ? e.g. |
Is there some "correct" way to solve this problem, since v3 now does not have support for priority any more? |
@Gramler priority has been indeed removed from the docker-compose file format v3 docs, but looking to the code i don't see any difference between v2 and v3 about network priorities (see https://github.com/docker/compose/blob/b01601a53cc8839afbe332f00d0d1b8165012e7b/compose/network.py#L313). In fact, a rapid test shows that priorities are just ignored, would you use v2 or v3 : https://gist.github.com/jfellus/cfee9efc1e8e1baf9d15314f16a46eca @karthanistyr seems correct ! Please tell me If you need help on this |
Any update on this mess? And just blindly taking the highest priority might not be the best idea in case of internal networks. So it might be more like:
|
the pieces have moved significantly in two years since I analysed it, so my comment above is most probably obsolete. |
afaik, https://github.com/docker/compose-cli isn't yet feature-complete with docker-compose. |
I'm running into even more issues when using the new |
Any updates? |
I year after the last ping... Still an issue. Alphabetically is bad if project name is added the the network name... |
+1 |
This really, really su**s badly. I don't understand why this is not a bigger issue, how are other people getting around this limitation or is this such an edge case? Or maybe I am rushing things, its barely been 8 years since this issue was created... |
try to solve it with a networking plugin or move on to alternatives such as podman |
|
I'm aware that this might not be an option for you - but I migrated all my projects to kubernetes in order to no longer deal with limitations or flaws of this kind |
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
docker network connect backend rose
docker exec rose ip r
The text was updated successfully, but these errors were encountered: