Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 61/ 160
04. Docker Networking

Container Network Model (CNM) & libnetwork Basics

Learn Docker CNM concepts: sandboxes, endpoints, and networks via libnetwork.

IntermediateCNM · libnetwork3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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}} api for 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

Loading interactive 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.

Concrete CNM setup

docker network create app-net; docker network connect --alias api app-net api; docker inspect -f {{json .NetworkSettings.Networks}} api

Key takeaway: Prove libnetwork with 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.

Deliberate failure test

Exercise this failure safely: changing the app listen address to fix a CNM problem when it is the missing network endpoint or firewall route.

Key takeaway: The model unifies drivers for operators; driver-specific behavior and IPAM still matter for macvlan, overlay and host networking.

How it works, step by step

Step 1 of 4
Design

1. 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.

Each container owns a network namespace, each attachment is an endpoint, and a driver gives the endpoints a shared network.
Key numbers at this step
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 disconnect in 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

Explicit CNM
Best for: Learn Docker CNM concepts: sandboxes, endpoints, and networks via libnetwork, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived libnetwork experiments with low blast radius.

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.

Managed Endpoints
Best for: Teams that centralize Endpoints policy across many workloads.

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}} api as proof and skipping inspect 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}} api address 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Disaster Recovery & Automated Volume Snapshot Workflows
Next topic
Default Docker Networks (bridge, host, none)