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.
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.
Combining previous answers with finding the container id based on the Docker image name.
For Windows containers use
where
<container>
is the name or the id of the container.You can use
docker ps
to find the id of the container.This will list down all the container IPs on the host:
The above works if the container is deployed to the default bridge network.
However, if using a custom bridge network or a overlay network, I found the below to work better:
First get the container ID:
(First column is for container ID)
Use the container ID to run:
At the bottom,under "NetworkSettings", you can find "IPAddress"
Or Just do:
Here's is a solution that I developed today in Python, using the "docker inspect container" JSON output as the data source.
I have a lot of containers and infrastructures that I have to inspect, and I need to obtain basic network information from any container, in a fast and pretty manner. That's why I made this script.
IMPORTANT: Since the version 1.9, Docker allows you to create multiple networks and attach them to the containers.
The output is just like this: