Docker Networking: Bridge vs Host vs Overlay
Fast recall
Quick revision
Core answer
Basic Docker networking knowledge and understanding of when each mode is appropriate
Exposing ports with -p when container-to-container communication is needed — unnecessary, use container names on the same network instead
Explain how docker-compose creates a bridge network automatically for each project, discuss DNS resolution by container/service name, and mention Kubernetes CNI as the production overlay equivalent
Interview-ready guide
Interview answer
Docker provides three main network drivers, and choosing the wrong one is the most common reason containers cannot communicate or performance is unexpectedly poor.
Bridge — the default for single-host communication
- Every Docker installation creates a default
bridgenetwork; containers on the same bridge can reach each other by IP, but not by name — user-defined bridge networks enable DNS-based service discovery, which is why you should always create a named bridge and never rely on the default - Create a user-defined bridge with
docker network create app-network; containers on it resolve each other by container name —http://postgres:5432works from a Spring Boot container if both containers join the same named bridge - The default bridge network requires you to use
--link(deprecated) for name resolution, which is why Docker Compose creates a project-specific network by default
Host — for performance-sensitive workloads
--network hostremoves the network namespace boundary; the container uses the host's network stack directly — no NAT, no port mapping overhead, but the container shares the host's IP and port space- A container on host networking binds ports directly on the host; two containers cannot both bind port 8080 on the same host network
- Appropriate for high-throughput, latency-sensitive workloads where NAT overhead is measurable — avoid it for most application containers because it reduces isolation
Overlay — for multi-host communication
- Overlay networks span multiple Docker hosts using VXLAN encapsulation; they are the foundation of Docker Swarm and Kubernetes pod networking
- Services on a Swarm overlay network communicate using the service name as hostname across any node in the cluster — the routing mesh handles which container on which host receives the request
- A misconfigured overlay is usually a firewall rule issue: UDP port 4789 (VXLAN) and TCP port 7946 (control plane) must be open between all nodes
Docker Networking: Bridge vs Host vs Overlay
Direct Answer
Bridge network (default) creates an isolated virtual network per host; containers communicate via container names. Host network removes network isolation — container shares the host network stack directly. Overlay network spans multiple Docker hosts (Swarm/Kubernetes) enabling cross-node container communication. Most Spring Boot apps use bridge locally and overlay (via CNI) in Kubernetes.
Common Mistakes & Pitfalls
Exposing ports with -p when container-to-container communication is needed — unnecessary, use container names on the same network instead
Check your understanding
Answer these without looking back at the article.
- How does Docker DNS resolution work within a bridge network?
- When would you use --network=host and what are the security implications?
- How does Kubernetes CNI relate to Docker's overlay network driver?
Related interview prep categories
2Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.