,

How to Inspect and Delete a Docker Network?

Posted by

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Docker networks allow containers to communicate with each other. Sometimes, you may need to clean up unused networks to free up resources. This tutorial will guide you through inspecting and deleting a Docker network, specifically the network named wizbrand_bridge in this case.

Prerequisites

  • Docker installed on your machine.
  • Terminal access to your Docker host (local machine, remote server, or cloud instance).

Step 1: List Docker Networks

Before deleting a network, it’s important to ensure that you are deleting the correct one. You can list all available Docker networks with the following command:

docker network ls

This will display a list of all Docker networks. You should see wizbrand_bridge (or the network you want to inspect) in the list.

Example Output:

NETWORK ID          NAME                  DRIVER              SCOPE
9ea1311e9a53        wizbrand_bridge       bridge              local

Step 2: Inspect the Network

To inspect a specific Docker network and view details about it, including its configuration, attached containers, subnet, and gateway, use the following command:

docker network inspect wizbrand_bridge

The output will show detailed information about the network, including the following key sections:

  • Name: The network’s name.
  • ID: The unique identifier for the network.
  • Driver: The network driver used (e.g., bridge).
  • Subnet: The IP subnet allocated for the network.
  • Gateway: The gateway for the network.
  • Containers: A list of containers attached to this network (if any).

Example Output:

[
    {
        "Name": "wizbrand_bridge",
        "Id": "9ea1311e9a53577591574b1a8bcca541d34be64e60184792a3899a5d42424131",
        "Created": "2025-04-11T09:43:15.804875185Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.19.0.0/16",
                    "Gateway": "172.19.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]

In this case, the "Containers": {} section is empty, indicating that no containers are currently using this network.

Step 3: Stop and Remove Containers (if any)

If the "Containers" section lists any containers, you need to stop and remove them before deleting the network.

To stop a container, use:

docker stop <container_name_or_id>

To remove the container, use:

docker rm <container_name_or_id>

Ensure that all containers are removed from the network before proceeding to delete it.

Step 4: Delete the Network

Once you have verified that no containers are using the network (or after stopping and removing them), you can safely delete the network.

To delete the network, run:

docker network rm wizbrand_bridge

This will remove the wizbrand_bridge network.

Step 5: Verify Network Deletion

To confirm that the network has been deleted, run the docker network ls command again. The wizbrand_bridge network should no longer appear in the list.

docker network ls

Example Output (after deletion):

NETWORK ID          NAME                  DRIVER              SCOPE

Troubleshooting

  • Error: “Network is in use”: If you encounter an error stating that the network is in use, ensure there are no containers connected to it. Use the docker network inspect command to check for attached containers. Stop and remove any containers that are using the network.
  • Error: “Network not found”: This means the network was already deleted. You can verify by running docker network ls.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x