Open In App

What Is Docker Network Inspect ?

Last Updated : 11 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

“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.

What is the Command to List all the Docker Networks

To list all the docker networks available in the docker use the below command.

docker network ls

docker network ls

You can see in the above image “docker network ls” lists all the networks available in the docker in my docker host there is one bridge network, one host network, one customized network nginx, and one none network

Type Of Networks In Docker

  • Bridge: If you build a container without specifying the kind of driver, the container will only be created in the bridge network, which is the default network.
  • Host: Containers will not have any IP address they will be directly created in the system network which will remove isolation between the docker host and containers.
  • None: IP addresses won’t be assigned to containers. These containments are not accessible to us from the outside or from any other container.
  • Overlay: An overlay network will enable the connection between multiple Docker demons and make different Docker swarm services communicate with each other.
  • IPvlan: Users have complete control over both IPv4 and IPv6 addressing by using the IPvlan driver.
  • Macvlan: macvlan driver makes it possible to assign MAC addresses to a container.

Read – Docker Networking

Steps To Inspect The Docker Network

Step 1: Choose the network that you want to inspect for that you need to list all the netowks in the docker for that use the following command.

docker network ls

Step 2: Use the following command to inspect the docker network.

docker network inspect my_network/Network Id

Step 3: Here i was inspecting my coutmized docker network as shown in the image below.

Screenshot-(658)

docker network inspect <Network_ID>

Why We Need To Inspect Docker Network

This JSON output represents information about a Docker network named “nginx.” Let’s break down the details provided in this network inspect output:

[
{
"Name": "nginx",
"Id": "0a1764302adfa32119cc4bc84dd5113f840e50356fe25398eeb7c6efeb18ff7f",
"Created": "2024-02-23T16:13:02.659550263Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]

To all the following details we will inspect the docker netowrk

  • Name: The name of the Docker network is “nginx.”
  • Id: The unique identifier (ID) of the Docker network.
  • Created: The timestamp indicating when the network was created.
  • Scope: The scope of the network (in this case, “local”).
  • Driver: The network driver used for this network (in this case, “bridge”).
  • EnableIPv6: Indicates whether IPv6 is enabled for the network (in this case, false).
  • IPAM: IP Address Management details for the network.
  • Driver: The IPAM driver used (in this case, “default”).
  • Config: The IP address configuration for the network, including the subnet and gateway.
  • Internal: Indicates whether the network is internal (false in this case).
  • Attachable: Indicates whether containers outside the network namespace can connect to this network (false in this case).
  • Ingress: Indicates whether the network is an “ingress” network (false in this case).
  • ConfigFrom: Indicates the source network from which the configuration was taken.
  • ConfigOnly: Indicates whether the network is used for configuration only (false in this case).
  • Containers: Details about containers connected to this network (empty in this case).
  • Options: Additional network options (empty in this case).
  • Labels: Labels associated with the network (empty in this case).

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.

Docker Network Inspect – FAQ’s

What does docker inspect do?

The docker inspect command is used to obtain detailed information about various Docker objects, such as containers, images, networks, volumes, and more.

How to check docker is active?

Use the following to check the docker status of the docker.

sudo systemctl is-active docker

Can I ping a docker container?

Yes, you can ping a Docker container from another container or from the host machine. Here are the general steps:

ping <container_ip_address>



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads