Its very difficult to keep track multiple Docker containers in the host machine. Moreover, if we are on a network or using compose, there might be several containers running inside the network. In that case, finding of which container is actively running and which has failed, is very difficult. We might need to trace out these containers periodically to check their status. For this, we need to have the IP addresses of the containers.
You can easily get the IP address of any container if you have the name or ID of the container
By default, the container is assigned an IP address for every Docker network it connects to. And each network is created with a default subnet mask, using it as a pool later on to give away the IP addresses.
Usually Docker uses the default 172.17. 0.0/16 subnet for container networking.
$ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' [CONTAINER_ID>] or [CONTAINER_NAME]
172.17.0.5
These commands will return the Docker container's IP address.
Comments (0)