How to get the IP address of the docker host from inside a docker container

xiamx picture xiamx · Apr 8, 2014 · Viewed 395k times · Source

As the title says. I need to be able to retrieve the IP address the docker hosts and the portmaps from the host to the container, and doing that inside of the container.

Answer

spinus picture spinus · Jul 12, 2014
/sbin/ip route|awk '/default/ { print $3 }'

As @MichaelNeale noticed, there is no sense to use this method in Dockerfile (except when we need this IP during build time only), because this IP will be hardcoded during build time.