Container Network Model (CNM) & libnetwork Basics
Learn Docker CNM concepts: sandboxes, endpoints, and networks via libnetwork.
In plain words
Each container owns a network namespace, each attachment is an endpoint, and a driver gives the endpoints a shared network.
Think of it like…
A sandbox is an apartment, an endpoint is its door into one hallway, and the network is that hallway with its route to the rest of the building.
Where you’ve seen it
In practice, docker network create app-net; docker network connect --alias api app-net api; docker inspect -f {{json .NetworkSettings.Networks}} api is the concrete move for this job: learn Docker CNM concepts: sandboxes, endpoints, and networks via libnetwork. The release is not accepted until inspect EndpointID, IPAddress, Gateway and NetworkID for app-net before and after disconnect confirms the result.
Words you’ll hear
- CNM
- The implementation control in
docker network create app-net; docker network connect --alias api app-net api; docker inspect -f {{json .NetworkSettings.Networks}} apifor learn Docker CNM concepts: sandboxes, endpoints, and networks via libnetwork. - libnetwork
- The result to observe with
inspect EndpointID, IPAddress, Gateway and NetworkID for app-net before and after disconnect, rather than infer from a successful command alone. - Endpoints
- The production boundary exposed when changing the app listen address to fix a CNM problem when it is the missing network endpoint or firewall route.
Visual diagram
Theory & deep dive
CNM control path
The concrete mechanism is docker network create app-net; docker network connect --alias api app-net api; docker inspect -f {{json .NetworkSettings.Networks}} api. The observable result is inspect EndpointID, IPAddress, Gateway and NetworkID for app-net before and after disconnect; if those disagree, inspect the runtime evidence before changing unrelated settings.
Learn Docker CNM concepts: sandboxes, endpoints, and networks via libnetwork. Keep CNM, libnetwork and Endpoints in the same deployment record so the intent and the observed state cannot drift apart.
docker network create app-net; docker network connect --alias api app-net api; docker inspect -f {{json .NetworkSettings.Networks}} api
inspect EndpointID, IPAddress, Gateway and NetworkID for app-net before and after disconnect, not with command success alone.Endpoints failure boundary
CNM vocabulary makes docker network behavior less magical: a multi-homed container has two endpoints, disconnect removes one endpoint without stopping the app, and driver scope determines whether a network is local or multi-host. The narrow failure to design for is changing the app listen address to fix a CNM problem when it is the missing network endpoint or firewall route.
Accept this compromise explicitly: The model unifies drivers for operators; driver-specific behavior and IPAM still matter for macvlan, overlay and host networking. The controlled check-inspect EndpointID, IPAddress, Gateway and NetworkID for app-net before and after disconnect-also identifies the point where a different design is safer.
Exercise this failure safely: changing the app listen address to fix a CNM problem when it is the missing network endpoint or firewall route.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: CNM vocabulary makes docker network behavior less magical: a multi-homed container has two endpoints, disconnect removes one endpoint without stopping the app, and driver scope determines whether a network is local or multi-host.
- Intent
- CNM
When to use it & trade-offs
What it is
Docker’s Container Network Model has three pieces: a sandbox containing a container network stack, an endpoint such as a veth pair, and a network that joins endpoints. libnetwork selects a driver and configures addresses, routes, DNS and service connectivity around that model.
Why it matters: CNM vocabulary makes docker network behavior less magical: a multi-homed container has two endpoints, disconnect removes one endpoint without stopping the app, and driver scope determines whether a network is local or multi-host.
When to reach for it
- The fit is strongest for this job: learn Docker CNM concepts: sandboxes, endpoints, and networks via libnetwork. Pair it with
inspect EndpointID, IPAddress, Gateway and NetworkID for app-net before and after disconnectin the runbook. - Production CNM changes should make libnetwork observable through
docker network create app-net; docker network connect --alias api app-net api; docker inspect -f {{json .NetworkSettings.Networks}} api, rather than trusting the runtime default. - Keep a rollback example for the case where changing the app listen address to fix a CNM problem when it is the missing network endpoint or firewall route.
When to avoid or be careful
- Do not accept command success while the system can still fail by changing the app listen address to fix a CNM problem when it is the missing network endpoint or firewall route.
- Avoid erasing Endpoints protection merely to dodge this cost: “The model unifies drivers for operators; driver-specific behavior and IPAM still matter for macvlan, overlay and host networking”.
- Do not replace the evidence path-
inspect EndpointID, IPAddress, Gateway and NetworkID for app-net before and after disconnect-with a screenshot or a mutable tag.
docker network create app-net; docker network connect --alias api app-net api; docker inspect -f {{json .NetworkSettings.Networks}} api: practical choices
Strengths: Docker’s Container Network Model has three pieces: a sandbox containing a container network stack, an endpoint such as a veth pair, and a network that joins endpoints. libnetwork selects a driver and configures addresses, routes, DNS and service connectivity around that model.
Watch out: The model unifies drivers for operators; driver-specific behavior and IPAM still matter for macvlan, overlay and host networking.
Strengths: It can begin with docker network create app-net; docker network connect --alias api app-net api; docker inspect -f {{json .NetworkSettings.Networks}} api and fewer surrounding controls.
Watch out: It silently accepts changing the app listen address to fix a CNM problem when it is the missing network endpoint or firewall route, which makes the result hard to reproduce after promotion.
Strengths: CNM vocabulary makes docker network behavior less magical: a multi-homed container has two endpoints, disconnect removes one endpoint without stopping the app, and driver scope determines whether a network is local or multi-host.
Watch out: The platform adds an ownership and debugging layer; retain inspect EndpointID, IPAddress, Gateway and NetworkID for app-net before and after disconnect as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker network create app-net; docker network connect --alias api app-net api; docker inspect -f {{json .NetworkSettings.Networks}} api
- inspect EndpointID, IPAddress, Gateway and NetworkID for app-net before and after disconnect
- Failure signature: changing the app listen address to fix a CNM problem when it is the missing network endpoint or firewall route
- Trade-off: The model unifies drivers for operators; driver-specific behavior and IPAM still matter for macvlan, overlay and host networking.
Benchmarks & rules of thumb
- 3 CNM parts
- sandbox, endpoint and network
- 1 endpoint/NIC
- created per network attachment
- 2 scopes
- local and swarm/global are typical
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker network create app-net; docker network connect --alias api app-net api; docker inspect -f {{json .NetworkSettings.Networks}} apias proof and skippinginspect EndpointID, IPAddress, Gateway and NetworkID for app-net before and after disconnect. - Changing the app listen address to fix a CNM problem when it is the missing network endpoint or firewall route
- Optimizing CNM without accepting that the model unifies drivers for operators; driver-specific behavior and IPAM still matter for macvlan, overlay and host networking.
Likely interviewer follow-ups
- Why does
docker network create app-net; docker network connect --alias api app-net api; docker inspect -f {{json .NetworkSettings.Networks}} apiaddress CNM here rather than through application code? - How would you distinguish healthy libnetwork from the failure “changing the app listen address to fix a CNM problem when it is the missing network endpoint or firewall route” using
inspect EndpointID, IPAddress, Gateway and NetworkID for app-net before and after disconnect? - When would this trade-off-“The model unifies drivers for operators; driver-specific behavior and IPAM still matter for macvlan, overlay and host networking”-justify a different Endpoints design?
docker network create app-net; docker network connect --alias api app-net api; docker inspect -f {{json .NetworkSettings.Networks}} api-and one proof-inspect EndpointID, IPAddress, Gateway and NetworkID for app-net before and after disconnect. Then name the boundary: changing the app listen address to fix a CNM problem when it is the missing network endpoint or firewall route.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Container Network Model (CNM) & libnetwork Basics with generative AI interview Q&A and hands-on practice.