cli icon indicating copy to clipboard operation
cli copied to clipboard

Feature request for docker run: Ability to connect to multiple networks

Open felixb95 opened this issue 4 years ago • 3 comments

Hi,

most of my containers are connected to multiple networks. Unfortunately, I have to run docker run --net mynet-1 -d --name alpine alpine and then docker network connect mynet-2 alpine for each container because the CLI doesn't support connecting a container to multiple networks at once.

It would be great if I could specify multiple networks at once in a single run command.

docker run --net mynet-1 --net mynet-2 -d --name alpine alpine

Would this be possible to implement? --net mynet-1,mynet-2 would also be an option. It probably would be enough if the CLI called the API for connecting the container to the second network, just as if network connect had been executed.

felixb95 avatar Apr 20 '20 15:04 felixb95

I would highly appreciate having such a feature included in Docker.

There is a use case I had yesterday, where I needed to set sysctl values for some network interfaces (e.g --sysctl net.ipv4.conf.eth1.rp_filter=0), however since eth1 did not exist after issuing the initial "docker run" command, I couldn't set this value for the particular interface ( And of course I wanted to avoid --privileged)

Were there any historic reasons or technical limitations why this feature wasn't included in the first place?

bka-dev avatar May 23 '20 09:05 bka-dev

This is partially fixed now. It is supported in the CLI, however this piece to make it work in the engine is not implemented yet: https://github.com/docker/cli/pull/1767#issuecomment-475195962

david-l-riley avatar Sep 02 '21 14:09 david-l-riley

Is there any progress to add support to define multiple networks directly via docker run? :slightly_smiling_face:

jakub-frajt avatar May 25 '22 15:05 jakub-frajt