While working with Docker, developers create and run a lot of containers in their host machine. Sometimes, it becomes really hard for developers to keep track of all the existing containers. Additionally, if you are using compose or network, there might be multiple containers executing inside the network.
If the container is executed with the default container networking. It means that the container is utilizing the built-in functionality of Docker networking for communicating with other containers and the host system. To determine which container is executing and which has stopped, developers should have the IP addresses of these containers.
This guide will provide different commands for getting the IP address of the Docker container from the host on Windows.
How to the IP Address of the Docker Container from the Host on Windows?
To find the IP address of the Docker container from the host on Windows, the below-listed commands are used:
Using “docker network inspect”
To get the IP address of the Docker container, first, list and select the Docker image for generating a new container by executing the following command:
From the below-given output, we have selected the elic Docker image:
Then, use the docker container run command to create a new Docker container using the selected image:
As you can see, our new container has been created successfully:
Next, list currently running containers through the docker ps command for verification:
Finally, execute the docker inspect command to display the IP address of the Docker container:
After running the above-given command, it will display the detailed information about the particular container:
Scroll down the terminal and find the “IPAddress” field. The IP address of the currently working container named vital_con1 is 172.17.0.3:
Using “docker exec”
The /etc/hosts file inside a container is a system file that is used for mapping the hostnames to the IP addresses including the IP address assigned to the container itself. To retrieve this IP address, run the docker exec -it command.
After doing so, you will be moved to the interactive shell session. Now, execute the cat command to show the available data of the /etc/hosts file:
As you can see, the IP address of the particular container has been retrieved successfully:
Using “docker network inspect”
As we know, by default containers are connected to the bridge network. We can inspect the network to find out the IP address of the container by executing the docker network inspect <network-name> command. To do so, first, run the provided command to display existing networks:
Here, we have selected the bridge network for further process:
Now, run the below-stated command along with the network name as bridge:
After executing the above command, scroll down to the Containers block and locate the IPV4Address field:
We have provided the easiest way to find the Docker container’s IP address from the host on Windows.
Conclusion
There are different commands that are used to get a Docker container’s IP address from the host on Windows, such as docker network inspect <container-id>, docker exec -it <container-name> /bin/bash, and the docker network inspect bridge commands. This blog illustrated the different ways to retrieve the IP address of the Docker container from host.