Use it when containers cannot reach each other, the internet, or be reached from outside.
Container Networking
Container networking connects containers to each other and the outside: Docker bridge networks with NAT and port publishing, host networking, and in Kubernetes a flat pod network provided by a CNI plugin plus Services for stable access.
1. Inside: docker exec <c> getent hosts <name> / kubectl exec <pod> -- nslookup <svc>.
2. IP and route inside the container.
3. Published port / Service endpoints present?
4. Listening address inside (ss -ltn).
5. Firewall/NetworkPolicy.
container netns → veth → bridge/CNI → routing/NAT → service/ports
Typical failures include an application bound only to loopback, wrong published port, missing return path, overlapping subnets, DNS/service-name confusion, MTU problems on overlays and policy/NAT rules that differ between host and namespace. Preserve the first divergent observation and repeat the same bounded verification after remediation.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Networking owns general routing/switching/protocol depth. Containers owns container namespace, bridge, overlay, port-publishing and CNI behavior as it affects workloads.
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification workflow Verify boundary
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Subtopics
Go one level deeper into this subject.
A bridge network connects containers on one host through a Linux bridge and NAT; user-defined bridges also provide name-based DNS between containers.
Subtopic Published Ports and Port MappingPublishing (-p host:container) forwards traffic arriving on a host port to a container port, using DNAT rules and docker-proxy.
Subtopic Container DNS ResolutionContainers get DNS settings from the runtime: Docker's embedded resolver on user-defined networks, or CoreDNS through /etc/resolv.conf in Kubernetes Pods.
Subtopic Container Network Interface (CNI)CNI plugins create Pod network interfaces and IP addresses on Kubernetes nodes; the chosen plugin (Calico, Cilium, Flannel and others) decides routing and policy.
Test from inside the container. Containers reach each other by name only on user-defined networks (Docker) or via Service DNS (Kubernetes). Apps must listen on 0.0.0.0, not 127.0.0.1.
docker ps -a— containers and exit codesdocker logs <c>— container outputdocker inspect <c>— config, mounts, network, state
ReferenceWhat it is1 section · depth on demand
Operating model
Container Networking explains how container namespaces connect to host interfaces, bridges, NAT, overlays and service-discovery systems. The critical distinction is between the application listen socket inside the container, namespace reachability, host-side publication and any upstream routing/firewall path.
ReferenceHow it works1 section · depth on demand
In depth
Container networking connects containers to each other and to the outside world. On a single host, containers get interfaces in their own network namespace, usually attached to a Linux bridge with NAT for outbound traffic and port publishing for inbound. In Kubernetes, CNI plugins give every pod a routable IP.
| Mode | Behaviour |
|---|---|
| Bridge (default Docker) | Private subnet, NAT outbound, -p host:container inbound |
| Host | Shares host network stack — no isolation, no port mapping |
| macvlan/ipvlan | Container appears directly on the LAN |
| Overlay | Multi-host networks (VXLAN) |
| None | No networking |
| CNI plugin (Kubernetes) | Notes |
|---|---|
| Calico | Routing (BGP) or overlay, network policies |
| Cilium | eBPF dataplane, policies, observability |
| Flannel | Simple overlay, no policies on its own |
docker network inspect bridge
ip netns list; nsenter -t <pid> -n ip addr # inspect a container's namespace
Published Docker ports bypass host firewall rules (ufw/firewalld) because Docker programs its own iptables/nftables rules — use the DOCKER-USER chain or bind to specific addresses.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
Assumptions: Two containers on one host. Replace names and subnet.
docker network create --driver bridge --subnet 172.30.0.0/24 appnet
docker run -d --name db --network appnet postgres:16
docker run -d --name api --network appnet -p 8080:8080 myorg/api:1.0Expected output
docker exec api getent hosts dbExpected state: The api container resolves db through Docker's embedded DNS to an address in the appnet subnet.
172.30.0.2 dbName resolution works only on user-defined networks, not the default bridge. Reachability of the database port is a separate check. Illustrative authored output: field layout matches the tool, values will differ in your environment.Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Documentation verification: confirms the upstream model used by the Topic. It does not assert local production behavior.
Basis: https://docs.docker.com/engine/network/ · confidence 92%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Container Networking verification boundary matrix
A compact lookup separating intent, owning component state, effective state and consumer-visible outcome for Container Networking.
| Boundary | Inspect | Healthy interpretation | Do not infer |
|---|---|---|---|
| Intent | Bridge networking | Intended object/scope is explicit and versioned where relevant | Intent is already effective |
| Owning runtime/control plane | Host networking / Port publishing and NAT | Owner accepts and reports the expected object state | Downstream dependencies are healthy |
| Effective state | Overlay networking | Independent read-back matches the intended state | Every client sees the same result |
| Consumer outcome | macvlan/ipvlan concepts | The original bounded check succeeds in the same time window | Production correctness outside this scope |
Deep reference
Design & tradeoffs
Scope
Networking owns general routing/switching/protocol depth. Containers owns container namespace, bridge, overlay, port-publishing and CNI behavior as it affects workloads.