Can I get ip address inside my docker container?

Kroid picture Kroid · Dec 27, 2014 · Viewed 43.1k times · Source

How to get container ip address inside this container?

'docker inspect $hostname ...' not suitable, because I don't share /var/run/docker.sock host file to container.

Answer

Victor Roetman picture Victor Roetman · Mar 30, 2016

I can find the IP address with

hostname -i

Of course, that may not be completely accurate if there is more than one interface.

Edit

Note: According to the hostname man page, hostname -i uses DNS to resolve the ip address, where hostname -I displays all the addresses except loopback, does not depend on DNS, and is recommended.

In all my Docker containers, -i and -I return the same results (but this is not the case on my desktop).