Skip to main content
In this lesson, we explore Docker networking, covering built-in modes and Linux network namespaces. You’ll learn how Docker uses a bridge network, veth pairs, and iptables NAT to connect containers and expose services.

Docker Networking Modes

Docker offers several network modes on a single host (e.g., host IP 192.168.1.10 on eth0): none
The container only has a loopback interface and cannot send or receive external traffic.
host
Containers share the host network namespace directly.
Using --network host removes network isolation. Ports in the container map directly to the host and may conflict with other services.
bridge
The default mode creates a docker0 bridge with a 172.17.0.0/16 subnet. Containers receive an IP on this network.
List Docker networks and host interfaces:
You’ll see an interface named docker0:
Inspect its IP address:

Docker and Network Namespaces

Each container runs in its own Linux network namespace. To view Docker namespaces on the host:
Inspect a container’s sandbox and namespace path:
When a container starts, Docker creates a veth pair:
  • One end attaches to the host bridge (docker0).
  • The other end goes inside the container namespace as eth0.
Host side:
Container side:
Each new container repeats this process, assigning a unique IP in 172.17.0.0/16.
The image is a network diagram illustrating a Docker bridge network setup, showing connections between containers and the bridge interface docker0.

Container-to-Container and Host Communication

Containers on the same bridge can communicate by IP. The host also reaches them directly:
External clients cannot access container IPs on the bridge network without port publishing.

Publishing Ports (Port Mapping)

Expose container ports to external clients with -p hostPort:containerPort:
Access via http://192.168.1.10:8080:

Behind the Scenes: iptables NAT

Docker adds iptables NAT rules to forward traffic:
This ensures incoming connections on host port 8080 are redirected to the container’s port 80.

References

Watch Video