8000 control network interface order for containers by fanjiyun · Pull Request #40974 · moby/moby · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

control network interface order for containers #40974

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

Conversation

fanjiyun
Copy link
Contributor
@fanjiyun fanjiyun commented May 15, 2020

Signed-off-by: fanjiyun fan.jiyun@zte.com.cn

- What I did
libnetwork allows setting the priority of network interface, but I'm not sure why there's no api to support it. So, I made some changes to allow the user to control the network interface order for containers.
related issue: #25181

Relevant PRs:
moby/libnetwork#2550 (open)
docker/cli#2529(open)

- How I did it
add some options for docker create, docker run, docker network connect. i.e.,

$ docker create --network name=my-network,priority=1 mynginx
$ docker run --network name=my-network,priority=2 mynginx
$ docker network connect --priority 3 my-network my-container

priority deafult to 0, and the higher the value, the higher the priority of the network interface

- How to verify it

$ docker create --name t1 --network name=net1,priority=1 mynginx sleep 1000
$ docker network connect --priority 2 net2 t1
$ docker network connect --priority 3 net3 t1
$ docker start t1

network interface order: net3 > net2 > net1

$ docker exec t1 ifconfig  
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.0.2  netmask 255.255.0.0  broadcast 172.20.255.255  ---net3
		...
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.19.0.3  netmask 255.255.0.0  broadcast 172.19.255.255  ---net2
		...
eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.18.0.3  netmask 255.255.0.0  broadcast 172.18.255.255  ---net1
		...

or

$ docker run -d --name t1 --network name=net1,priority=1 mynginx:v1 sleep 1000
$ docker network connect --priority 2 net2 t1
$ docker network connect --priority 3 net3 t1
$ docker restart t1  (container restart required)

$docker exec t1 ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.0.2  netmask 255.255.0.0  broadcast 172.20.255.255  ---net3
		...
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.19.0.2  netmask 255.255.0.0  broadcast 172.19.255.255  ---net2
        ether 02:42:ac:13:00:02  txqueuelen 0  (Ethernet)
		...	
eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.18.0.2  netmask 255.255.0.0  broadcast 172.18.255.255  ---net1
        ether 02:42:ac:12:00:02  txqueuelen 0  (Ethernet)
		...

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

Signed-off-by: fanjiyun <fan.jiyun@zte.com.cn>
@fanjiyun
Copy link
Contributor Author
fanjiyun commented May 15, 2020

It depends on vendor moby/libnetwork#2550.
But I don't know what I should do for vendor?

@thaJeztah thaJeztah added area/networking kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/2-code-review labels Oct 31, 2020
@Vlad1mir-D
Copy link

Any updates? :)

Copy link
Member
@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ok.
Hunting through libnetwork this is poorly documented it seems like this is used to sort endpoints when adding them and as a key when deleting

I'd prefer if priority were set based on order of joins, unfortunately the API specifies this in a map which we cannot sort.

I'm curious what the need for priority is? Is this just to control interface names? It may be better to just provide a way to customize the name.
I also think the naming is a little confusing.

In any case, if we do add this we'll need the field to be added to the api docs.
https://github.com/moby/moby/blob/master/api/swagger.yaml
Also a doc string on the type would be helpful.

@cpuguy83 cpuguy83 requested a review from corhere April 28, 2023 15:13
@corhere
Copy link
Contributor
corhere commented Apr 28, 2023

In addition to controlling the interface names, the order of endpoint joins may have something to do with which interface's gateway becomes the default gateway for the container. @neersighted and I were just talking about default gateways last week! I would also prefer allowing interface names, and which interface is the default gateway, to be set explicitly over doing it in a roundabout fashion with priority.

@thaJeztah
Copy link
Member

The related ticket was for controlling the interface name when joining a network. At the time it was created, we didn't have per-network options, but with the advanced sytax that was added, at least the UX would now allow it;

One thing to look into for that is that currently the API does not allow multiple networks to be specified when creating a container. This effectively is an "artificial" limitation; it was blocked at the time because the UX didn't allow for this, but the CLI already was updated to support it. I asked @akerouanton to look if there's actual technical reasons remaining to not allow it (and if not, to remove that error, and support it).

@akerouanton
Copy link
Member

This was implemented in #48936, so let me close this PR. Thanks for your contribution!

@akerouanton akerouanton closed this Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/networking kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/2-code-review
4A21 Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0