简体   繁体   中英

Identify overlay networks from the inside of the container

I have a process inside my docker container that is attached to multiple overlay networks and it must only bind to a specific overlay network interface (it knows its name through passed env vars) so that the rest of the containers in that overlay network would be able to talk to it.

How can a container identify which one of its given network interfaces is which overlay network interface from the inside?

If you already know the network details then you can run the following inside the container to get the hostname :

hostname -i

This will provide you with the overlay network's ip.

Another way will be to pass the Network name as a runtime argument , like so :

docker run --name=myname -e NETWORK=MY_NETWORK --net=MY_NETWORK 

And inside the container :

echo $NETOWRK
MY_NETWORK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM