Skip to content

control network interface order for containers - #2529

Closed
fanjiyun wants to merge 1 commit into
docker:masterfrom
fanjiyun:control-network-interface-order-for-containers
Closed

control network interface order for containers#2529
fanjiyun wants to merge 1 commit into
docker:masterfrom
fanjiyun:control-network-interface-order-for-containers

Conversation

@fanjiyun

Copy link
Copy Markdown

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)
moby/moby#40974 (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
Copy Markdown
Author

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

@Vlad1mir-D

Copy link
Copy Markdown

Is this going to be merged?

@akerouanton

Copy link
Copy Markdown
Member

This was implemented in moby/moby#48936 and #5664. 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

None yet

4 participants