Skip to content
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 network interface order for containers #2529

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fanjiyun
Copy link

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
Author

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

@Vlad1mir-D
Copy link

Is this going to be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants