I just wanted to make sure other noobs don't make my mistake and try to get the IP from the image instead of the container. Ensure you get the CID or container id and query that; CID via 'docker ps' that is.
– Paul GregoireJan 19 '15 at 18:06

How to get vice versa? Host IP or call from container?
– Somnath MulukOct 4 at 14:37

!WARNING! This doesn't work anymore. The new format is specific to the container and follows the form {{ .NetworkSettings.Networks.$network.IPAddress }}. The default appears to be bridge, but under docker-compose this will be a specific name that depends on the name of your app (I think from the --project-name flag, though that's also going to depend on what type of networking config you have set up). I wrote a full answer in an answer here stackoverflow.com/questions/17157721/…
– DunkFeb 10 '16 at 15:46

10

The answer doesn't work anymore. Run this command to get the IP - docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${CID}
– Kasun GajasingheJul 8 '16 at 6:45

I really like this but it doesn't work for Docker Compose as well, something to do with having their own network. Instead change {{.NetworkSettings.IPAddress }} to {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}
– clockworkgeekMar 13 '16 at 16:57

That can be simplified quite a bit - use docker ps -q to avoid the tail, and --format to avoid the grep. Also you can pass multiple container IDs to docker inspect rather than loop in shell.
– BryanMay 6 '15 at 10:45

1

docker ps -q only displays the containers' numeric IDs, but I think using their name is better. tail is only to get rid of the first line (table header) & is still needed. I could use --format, though: docker ps | tail -n +2 | while read -a a; do name=${a[$((${#a[@]}-1))]}; echo -ne "$name\t"; docker inspect --format="{{.NetworkSettings.IPAddress}}" $name | cut -d \" -f 4; done. But that doesn't seem like a big improvement... the grep was more readable IMO.
– Marco RoyMay 8 '15 at 1:01

For me, the IP address was on the "Hostname/ports" tab, but this was nevertheless a very helpful answer! Note that docker inspect does not work when you run docker toolbox. It will report an IP address, but it is not the correct address that your services will use.
– Göran RoseenSep 10 at 12:55

For those who came from Google to find solution for command execution from terminal (not by script), jid (an interactive JSON drill down util with autocomplete and suggestion) let you achieve same thing with less typing.

While this link may answer the question, link only answers are discouraged on Stack Overflow, you can improve this answer by taking vital parts of the link and putting it into your answer, this makes sure your answer is still an answer if the link gets changed or removed :)
– WhatsThePointDec 4 '17 at 13:30

Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).