简体   繁体   中英

How to get the ip address of the docker host (which will be used in containers) from the host itself

I want to run a container and pass it the host IP (which will be visible by the container) as an environment variable to my container, how can I do that ?

Here is what it should like:

docker run -it --rm -e HOST_IP=`script which will give me the host IP visible by the future running container` myimage
docker run -it --rm -e HOST_IP=`/sbin/ip route | awk '/docker/ {print $9 }'` myimage

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