Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a Docker container's IP address from the host

Is there a command I can run to get the container's IP address right from the host after a new container is created?

Basically, once Docker creates the container, I want to roll my own code deployment and container configuration scripts.

like image 923
Murali Allada Avatar asked Jun 17 '13 22:06

Murali Allada


People also ask

How do I find the IP of a Docker container?

You can easily get the IP address of any container if you have the name or ID of the container. You can get the container names using the "Docker ps -a" command. This will list all the existing containers.

How do I find my Docker Bridge IP address?

Inspect the bridge network to see what containers are connected to it. Near the top, information about the bridge network is listed, including the IP address of the gateway between the Docker host and the bridge network ( 172.17. 0.1 ).


1 Answers

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

Modern Docker client syntax is:

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

Old Docker client syntax is:

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

These commands will return the Docker container's IP address.

As mentioned in the comments: if you are on Windows, use double quotes " instead of single quotes ' around the curly braces.

like image 132
WouterD Avatar answered Sep 24 '22 00:09

WouterD