Network
In one line
Container networking defines how containers communicate with each other, the host, and external networks.
In simple words
Container networking is about how containers talk to each other and to the outside world. Since containers are isolated, they need networking rules to communicate.
In Docker, the default bridge network lets containers on the same host communicate. You can also create custom networks for better isolation and DNS resolution (containers can reach each other by name).
In Kubernetes, networking is more sophisticated. Every Pod gets its own IP address, and Pods can communicate with any other Pod in the cluster without NAT. Services provide stable addresses, NetworkPolicies control traffic flow, and Ingress manages external access.
Example
# Docker: create a custom network
docker network create mynet
# Run containers on the same network
docker run --network mynet --name api myapi
docker run --network mynet --name web myweb
# 'web' can now reach 'api' by hostname: http://api:3000Containers on the same custom network can reach each other by container name as hostname.
How it works
- Docker creates a virtual bridge or overlay network.
- Each container gets a virtual ethernet interface and IP.
- Containers on the same network can communicate by IP or DNS name.
- Kubernetes assigns each Pod an IP and handles routing across nodes.
Common confusions
Confused with: Service
The difference: Networking is the underlying communication mechanism; a Service is a Kubernetes abstraction that provides a stable address on top of the network.
Related terms
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.