docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' [컨테이너의 이름 혹은 ID]



이렇게 해주면 바로 해당 container가 사용중인 ip 주소가 뽑힌다.




up vote



아래서 퍼왔습니다.


https://stackoverflow.com/questions/17157721/how-to-get-a-docker-containers-ip-address-from-the-host




The --format option of inspect comes to the rescue.

Modern Docker client syntax:

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id

Old Docker client syntax:

docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_name_or_id

Which will return just the IP address.

  • 23
    This is a much, MUCH better solution. Only ask for what you need, if possible! – MikeyB Jan 7 '14 at 2:19
  • 18
    Just a note. The single dash options are being deprecated so that -format will become --format. – jamtur01Mar 22 '14 at 1:42 
  • 6
    Hmm. Getting a <no value> response on a Mac using Fig/Boot2Docker – cevaris Nov 24 '14 at 14:57
  • 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/… – Dunk Feb 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 Gajasinghe Jul 8 '16 at 6:45



+ Recent posts