Cloud Native 6 min read

Understanding Docker0 and Custom Docker Networks: Practical Examples

This article walks through Docker's default docker0 bridge, explains how containers obtain IP addresses via veth‑pair interfaces, demonstrates inspecting container IPs, and shows how to create and use custom bridge networks so containers can communicate by name or IP, including adding existing containers to the new network.

The Dominant Programmer
The Dominant Programmer
The Dominant Programmer
Understanding Docker0 and Custom Docker Networks: Practical Examples

Understanding docker0

After installing Docker on CentOS 7, the author runs a Tomcat container to explore how Docker handles container networking. docker run -d --name tomcat01 tomcat From the host, pinging the container's IP succeeds, confirming connectivity.

To retrieve a container's IP address, the command used is: docker inspect 3aaf where 3aaf is the container ID or name. The host's network interfaces are listed with: ip addr Each newly started container receives an IP address on the docker0 bridge, which is implemented using a veth‑pair. Starting a second container shows an additional pair of virtual interfaces: docker run -d --name tomcat02 tomcat Both containers can ping each other, demonstrating that they share the same bridge.

If the ping command is missing inside a container, the author installs it with:

apt update
apt install iputils-ping

Key conclusions:

All containers without an explicit network use the default docker0 bridge.

Docker automatically assigns a free IP address to each container.

Custom Docker Networks

In micro‑service scenarios, accessing containers by name or migrating IPs is often required, which the default bridge does not support.

Listing all Docker networks shows the available drivers:

docker network ls

The default bridge driver corresponds to docker0. It does not support name resolution, and using --link is discouraged.

To create a custom bridge network with a specific subnet and gateway:

docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 mynet

After creation, the network appears in the list and can be inspected:

docker network inspect mynet

Containers launched with the custom network can communicate by both IP and container name:

docker run -d -P --name tomcat-mynet-01 --net mynet tomcat
docker run -d -P --name tomcat-mynet-02 --net mynet tomcat

These two containers are mutually reachable via name or IP.

To connect an already running container (e.g., tomcat01) to the custom network:

docker network connect mynet tomcat01

After connecting, the container can communicate with the other containers on mynet, completing the custom network setup.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Dockerbridgecontainer networkingcustom networkveth-pairdocker0
The Dominant Programmer
Written by

The Dominant Programmer

Resources and tutorials for programmers' advanced learning journey. Advanced tracks in Java, Python, and C#. Blog: https://blog.csdn.net/badao_liumang_qizhi

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.