Networking: libnetwork and drivers
CNM is the blueprint. libnetwork is the engine that builds it, and drivers decide how the bits actually move.
key idea / Docker itselfcontainer / good pathhost / watch outproblem / blockedneutral
The networking stack
Choosing a driver
There are only a handful, and each answers one question.
| Driver | Scope | Container gets | Use it when |
|---|---|---|---|
bridge | local | private IP behind NAT | the default for one machine |
host | local | the host's own stack | you need raw speed and accept no isolation |
overlay | swarm | IP on a virtual multi-host network | containers on different hosts must talk |
macvlan | local | its own MAC and LAN IP | it must look like a real machine on the LAN |
none | local | only loopback | full network isolation |
Pluggable
Try it yourself
-
Step 1 · List networks and their drivers
$ docker network ls NETWORK ID NAME DRIVER SCOPE a1b2c3d4e5f6 bridge bridge local b2c3d4e5f6a1 host host local c3d4e5f6a1b2 none null local -
Step 2 · Read the driver from inspect
$ docker network inspect bridge --format '{{.Driver}} {{.Scope}}' bridge local -
Step 3 · Create a bridge, then remove it
--driver bridgeasks libnetwork for the built-in bridge driver.rmfails if a container is still attached.$ docker network create --driver bridge app $ docker network ls --filter name=app NETWORK ID NAME DRIVER SCOPE d4e5f6a1b2c3 app bridge local $ docker network rm app app
Recap
- libnetwork implements CNM inside the Docker daemon.
- A driver tells libnetwork how to move packets: bridge, host, overlay, macvlan, none.
- Scope matters:
localnetworks live on one host,swarmnetworks span hosts. - Third-party plugins use the same interface as the built-in drivers.
Quick check
In an interview: "How does Docker networking work?" What is a better answer than "it uses a bridge"?
Show answer
Describe the layers: the CNM model (sandbox, endpoint, network) implemented by libnetwork, which calls a driver such as bridge to create veth pairs, bridges and iptables rules in the kernel.