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.
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.
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 ).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With