How To Docker Network Inspect Container IP
To inspect the IP address of a Docker container within a specific Docker network, you can use the docker inspect command along with some filtering to extract the relevant information. Here’s a step-by-step guide:
Step 1: List all the containers which are running in the docker host for that use the command as mentioned below.
docker ps
Step 2: Use the docker inspect command to get detailed information about the container, and then filter the output to get the IP address. Replace <container_id> with the actual Container ID.
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_id>
- docker inspect: This command is used to obtain detailed information about Docker objects, such as containers, images, volumes, and networks.
- -f: This flag is used to format the output using a Go template. It allows you to specify a Go template to format the output in a custom way.
- ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’: This is the Go template used for formatting the output. Let’s break it down:
- {{range .NetworkSettings.Networks}}: This part starts a loop over the networks to which the container is connected. It iterates over the networks defined in the Networks section of the container’s network settings.
- {{.IPAddress}}: Within the loop, this part extracts the IP address of the container for the current network.
- {{end}}: This part marks the end of the loop.
What Is Docker Network Inspect ?
“docker network inspection” is the command used in the docker CLI to know the detailed information of a particular docker network. Docker network allows you to inspect the configuration and status of a specific Docker network in which you can find the IP address assigned to the docker network the containers connected and other docker network settings.