-
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
Control interface name in docker multiple networking #25181
Comments
So, essentially, in your case you can work around it through subnet filtering, right? e.g., you know that a given subnet has been assigned to a given network, thus you can filter your iface list and find the one which is the one assigned to your desired network. Did you go through this path? Or did something different? |
With the "csv" style syntax for networks being worked on (see #31964, and PR's docker/cli#62 (for services), and docker/cli#156 for ping @abhinandanpb @fcrisciani WDYT? |
@thaJeztah I believe one of the goals of the network-opt initially was to ensure symmetry between the service create and docker run. But this interface option would only apply to container create / network connect right ? |
@abhinandanpb would it be different for services and "regular" containers? i.e.;
For |
@thaJeztah I'm interested in being able to specify an explicit interface, so:
would be great...or something similar in I also use docker-compose, so would also need to be able to specify the interface in the services block of a container. Is there any likelihood that this will be implemented soon? |
+1 This is pretty serious, meaning that if you have more networks, the interfaces will get mixed up. Almost all network applications base themselves on the fact that the interface names are the same. Why would they be randomly assigned it is beyond my understanding, when it would have been much easier to assigned them in order at least based on the network name or the order the networks were connected to the container. |
I am interested in this as well. As a use case... Have a service that is in two networks... one for reverse proxying (frontend) and one for its own backend (backend). In order to receive traffic, the app (a Java app) needs to listen to the interface for the frontend. Since we aren't using static subnets, it's difficult to discover/know which interface we should use. The proposed solution above would work for us. |
I would definitely be interested in having Docker network interfaces have predictable names. Most software dealing with networking assumes you have static interface names, so I cannot use any of that with Docker networks, which is a pain. |
|
@ptman that's not the point. it's about the interface name inside the container |
This comment has been minimized.
This comment has been minimized.
@thaJeztah is that If it exists, how would it be used from Docker Compose? |
@thaJeztah any updates? It's pretty strange that interface name isn't configurable. From my POV it's obvious that most of real network interfaces have their own names, very different from assumed ethX. |
Also would like to see this resolved. |
Another +1 for getting this issue resolved (beyond having predictable interface order at least, for which @cziebuhr receives full credit)! |
+1 Yes, this is something we need. Since dockers are used widely in automated environments it would be very nice to have. |
+1 This would be very useful for vrrp in combination with ha-proxy containers to make sure that the keepalived config is setting up the VIP on the right interface. I am using macvlan interfaces to geologically control where the access happens on a larger distributed docker swarm. |
I'm sorry to sound sour, but for any but the most simplistic network use cases one obviously wants to have containers connected to multiple interfaces, and those interfaces of course have to have deterministic names. I'm surprised there is even a discsussion about it ?!? |
My Observium network monitor has literally thousands of randomly-named deleted docker interfaces. I would so love to be able to persistently name the interface myself in Swarm as part of |
In my recent testing I found that the interfaces were assigned alphabetically. So which ever network was given the alphabetically first name, that's the one that got the alphabetically first device name. Not sure how consistent that is but the rule held true for me 10 times in a row. |
I can verify @eyal0 's observation. It seems to result from this commit moby/libnetwork@c13db32 from 21. Mar 2018. It changed the way how interfaces are stored, from a heap to a list. There is also code for sorting the network interfaces, which resorts to comparing the interface's name, if their priority (sandbox_store.go#L28) is equal. The above referenced pull requests (control network interface order for containers) try to add the functionality to allow setting the priority when connecting a container to a network via Still I could not find a way to specify the network interface's name inside the container. The |
@eyal0 I can confirm to. See following gist to reproduce : https://gist.github.com/jfellus/cfee9efc1e8e1baf9d15314f16a46eca |
+1 This is something we need. I have an extra network for Traefik traffic for example and currently I have to do the alphabetical workaround to get the interfaces in the right order. Any updates on this? |
In our setup scripts we have the following lines:
it should be possible for docker connect to do something siimilar. |
Any updates on this? |
One obstacle I see w.r.t a possible implementation is the inherent definition of the networking sandbox interface, which requires that a prefix is given for the network link name. This is i.m.h.o presumptuous and leads to loss of generality. moby/libnetwork/osl/sandbox.go Lines 26 to 31 in 0b39cc2
Changing the argument name |
We could make any changes we need inside a container before it starts if we could run hooks on certain events (like network connect) so, can we run some external hooks when container is created or after certain events (i.e. docker network attached)? |
Using latest Docker and Docker Compose, I run a container that is connected to two networks. This container needs to connect to an IPv6 link-local address (LLA). Such a connection needs to specify a zone suffix (e.g. interface name). Since my container is connected to multiple networks, the container has multiple network interfaces (e.g. It is possible for an external script to query a MAC address from the Docker network for a particular container:
And then use that MAC address to determine the name of the associated network interface:
But I wish there was a more Dockery way to do this. I'm not quite familiar with the startup sequence, but could the container's internal interface name be externalized into an environment variable that I could pass to my container? |
I'm deploying containers that are supposed to form a cluster over a specific overlay network. All the containers are also connected to another network facilitating ingress traffic (Docker Swarm). If not specified, the application (out of my control) picks the interface to cluster on randomly. This obviously does not work, as the containers cannot communicate over the ingress network. I have the option to configure the application to listen on a specific IP, but as Swarm allocates the addresses dynamically as containers are created, I have a hard time providing the IP as a parameter during container startup. I also have the option to bind to a specific, named interface. This forces me to rely on having the overlay network mapped to a specific network inside the container (say, eth0). Being able to control network naming inside the container would make this significantly easier. |
Ok, so with little help I'm willing to implement this feature. I see two scenarios I could implement:
Of course this feature implies implementing also support in compose files for compose and stack. I just need some initial confirmation from staff (@thaJeztah ) that this will be merged, when ready. To add my use case to the big pile of use cases: Alex |
I don't think this should be a property of the network, but when attaching a network to a container (or service); see #25181 (comment)
docker compose can then use the option using the advanced syntax (similar to how services:
some-service:
networks:
some-network:
iface: my-eth
other-network:
iface: my-eth2 |
Excellent! See you in a bit. |
ran into something similar at a project I am working on, seems like the interface is chosen based on whats alphabetically lowest we have a on the other hand if i create a new network named |
Your comment saved my day! I can use this as a hack to establish the priority :) |
With the workaround suggested in #17796 for multiple network mode for docker containers, it is not possible to control the interface name with the
docker network connect
command. The order of the ethx interfaces afterdocker start
is not consistent with the sequence ofdocker connect
commands. Only the network added in thedocker create
command comes up as eth0 and is consistent.My post boot script relies on the name of the interfaces and won't work if the order is changed and I require the interfaces to be up on boot. So, I can't use
pipework
script with the-i
flag as well.Output of
docker version
:Output of
docker info
:Additional environment details: Running on a centos 7.1 bare metal.
uname -a
Linux "REDACTED" 3.10.0-229.20.1.el7.x86_64 #1 SMP Tue Nov 3 19:10:07 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Steps to reproduce the issue:
Results received: eth2 was assigned 10.100.4.3 and eth3 was assigned 10.100.3.3
Results expected: eth2 must be assigned 10.100.3.3 and eth3 must be assigned 10.100.4.3 or there needs to be a way to specify the interface name in
docker network connect
command.The issue happens occasionally and the probability of it occurring increases with the increase in the number of networks the container is connected to.
The text was updated successfully, but these errors were encountered: