Docker Inspect Network

In this guide, we'll deep dive into the docker inspect command for networks, exploring its usage and interpreting its output.

Why Inspect Docker Networks? 

Configuration Verification: Ensure that a network's settings match its intended configuration.

Debugging: Troubleshoot connectivity or configuration issues. 

Documentation: Keep a record of the network setup for documentation or reporting purposes. 

Inspecting a Docker Network

To inspect a Docker network, you'd typically use:

docker inspect NETWORK_NAME_OR_ID

For instance, to inspect a network named my_network:

$ docker inspect my_network
[
    {
        "Name": "my_network",
        "Id": "f7b1dca5d1a41ed6bd15f7ed74642f4b2b3a7e7447e6d9b6e264a4be8455b5fd",
        "Created": "2023-08-15T10:25:27.916512735Z",
        "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,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]

From the above output: 

Name: Name of the network. 

Id: Unique identifier for the network. 

Scope: Specifies the level at which the network operates (local, global, or swarm). 

Driver: The network driver used (bridge, host, overlay, macvlan, etc.). 

IPAM: IP Address Management, detailing the subnet and gateway associated with the network.

Containers: Lists containers associated with this network.

Inspecting Multiple Docker Networks

While docker inspect primarily targets individual entities, its design allows for multiple arguments, enabling the inspection of multiple networks simultaneously.

docker inspect NETWORK_NAME_1 NETWORK_NAME_2 ... NETWORK_NAME_N

For instance, to inspect networks named frontend_network and backend_network:

$ docker inspect frontend_network backend_network
[
    {
        "Name": "frontend_network",
        "Id": "a2b3f4g5h6j7k8l9p0o1i2u3y4t5r6e7w8e9r0t1",
        ...
        "IPAM": {
            ...
            "Config": [
                {
                    "Subnet": "172.18.1.0/24",
                    ...
                }
            ]
        },
        ...
        "Containers": {},
        ...
    },
    {
        "Name": "backend_network",
        "Id": "z9x8c7v6b5n4m3l2k1j0h9g8f7e6d5s4a3z2x1c2",
        ...
        "IPAM": {
            ...
            "Config": [
                {
                    "Subnet": "172.18.2.0/24",
                    ...
                }
            ]
        },
        ...
        "Containers": {},
        ...
    }
]

The output is a JSON array, each element representing the inspection details of the specified networks in the order they were listed in the command.

Conclusion

In this guide, we have seen how to inspect a single Docker network as well as inspect multiple Docker networks.

Related Networking Guides

Comments