Docker Community Forums

Share and learn in the Docker community.

Could a container bind a specific network interface to reach external network?

docker

(Triciac) #1

After surveying, I knew container can bind the exposed port to a specific network interface. But I think it’s works only for traffic which comes from external network to container.
I would like to assign a specific interface to a container so that the container can reach external network from the interface.
For example, I have two interface, eth0 and eth1. I want to bind a container to eht0. When Executing command “ping 8.8.8.8” in a container, the traffic should reach external network from eth0 consequently.
Could it be possible and how to achieve it ?
Thanks.


(Sam) #2

see --network string Connect a container to a network (default “default”)
on the docker run command

this might help


(Sreenivas Makam) #3

Hi
As you said, for traffic ingressing the container, we can control the interface using “-p” option. For traffic from container to external world, I think it uses host’s routing table. So there is no control at the container level, but can be controlled at host level.

Regards
Sreenivas


(Triciac) #4

Thank you! :grinning: