Docker Network Management

Docker Network Management

It's time to harness your skills and concepts learned from previous lessons to effectively manage Docker networks. This lesson focuses on providing you with essential commands and techniques for listing, inspecting, removing, and pruning networks. Network management is a vital skill in handling containerized applications, ensuring your environments remain organized and efficient. By mastering these commands, you will ensure smooth and efficient networking processes within your Docker setup.

Listing Docker Networks

Let's begin by learning how to list all the existing Docker networks. The docker network ls command is your go-to tool for this task. It displays a table of network names, IDs, and types.

For example, executing the command will output a detailed list of networks currently in your environment:

# List all networks
docker network ls

If you haven't created any additional networks, you might see an output similar to this, showing the default ones:

NETWORK ID     NAME         DRIVER    SCOPE
5ced7c00b3cc   bridge       bridge    local
eb929830749a   host         host      local
6227f1d2f9b8   none         null      local

These are the default networks Docker provides:

  • bridge: A bridge network is a private internal network created by Docker on the host. Containers on this network can communicate with each other and with external hosts.
  • host: A host network removes network isolation between the Docker host and the Docker containers to use the host's networking directly.
  • none: This network adds a container to a container-specific network stack without any network interfaces.

These default networks are foundational, but understanding network specifics requires a deeper dive, which we will explore next. To learn more about the docker network ls command, you can visit the official Docker network ls documentation.

Inspecting Docker Networks

Understanding the details of your networks is crucial for diagnosing and managing container connections. The docker network inspect <network_name> command provides comprehensive information about a network's settings, such as subnetting, connected containers, and driver configuration.

For example, inspecting the my_network network will yield output like:

# See details of a network
docker network inspect my_network

Key details include:

[
    {
        "Name": "my_network",
        "Driver": "bridge",
        "IPAM": {
            "Driver": "default",
            "Config": [
                {
                    "Subnet": "172.22.0.0/16",
                    "Gateway": "172.22.0.1"
                }
            ]
        },
        "Containers": {
            "d08d71e60ff48c4136e92535e082c7e8aea5590e931e743a393ce3675fd8b158": {
                "Name": "container2",
                "IPv4Address": "172.22.0.3/16"
            }
        },
        // Other details ...
    }
]
  • Name and Driver: The network's name ("my_network") and driver ("bridge") indicate it's a user-defined bridge network, allowing containers to communicate within this subnet.

  • IPAM Configuration: Specifies the IP address management settings, including subnet ("172.22.0.0/16") and gateway ("172.22.0.1"), crucial for defining the network's address space.

  • Containers Section: Lists connected containers, providing details such as the container's name ("container2") and its assigned IP ("172.22.0.3/16"), essential for understanding container communication paths within the network.

This command helps ensure network configurations align with your desired architecture, verifying connected container names and IPs within the network. For more detailed information about the docker network inspect command, refer to the official Docker network inspect documentation.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal