What Is a Docker Network?
Understand what a Docker network is, its bridge, host, overlay, and none drivers, and how containers discover each other by name via embedded DNS.
Expected Interview Answer
A Docker network is a virtual, software-defined network that lets containers discover and communicate with each other by name, while controlling what traffic can reach the host or the outside world.
Docker ships with built-in network drivers — bridge for isolated single-host communication, host for sharing the host's network stack directly, overlay for multi-host swarm communication, and none for full isolation. Containers attached to the same user-defined bridge network can resolve each other by container name through Docker's embedded DNS, which removes the need to hard-code IP addresses. Each network also acts as a security boundary, since containers on different networks cannot reach each other unless explicitly connected.
- Containers reach each other by name instead of hard-coded IPs
- Isolates groups of containers from each other for security
- Multiple driver types fit different deployment topologies
- Works consistently across single hosts and swarm clusters
- Easy to attach or detach containers without rebuilding images
AI Mentor Explanation
A Docker network is like the internal team radio channel that only players on one side can tune into during a match, letting the wicketkeeper call instructions to the bowler by name rather than shouting across the ground. Two teams practicing on adjacent nets use different channels so their signals never cross. The stadium's public address system is the shared host network everyone can still hear.
Step-by-Step Explanation
Step 1
Choose a driver
Pick bridge for single-host isolation, host to share the host's stack, overlay for multi-host swarm, or none for full isolation.
Step 2
Create the network
Docker allocates a subnet, gateway, and embedded DNS server for containers attached to it.
Step 3
Attach containers
Containers joined to the same network register their names with Docker's DNS so they can resolve each other.
Step 4
Name-based discovery
A container reaches another by its service or container name instead of a hard-coded IP address.
Step 5
Isolate by default
Containers on different networks cannot communicate unless explicitly connected to a shared network.
What Interviewer Expects
- Names the built-in drivers: bridge, host, overlay, none
- Explains embedded DNS-based service discovery by container name
- Understands network isolation as a security boundary between container groups
- Knows when to choose overlay networks for multi-host swarm setups
- Can describe how to connect a running container to an additional network
Common Mistakes
- Assuming all containers on a host can always reach each other
- Hard-coding container IP addresses instead of using names
- Confusing the default bridge network with a user-defined bridge network
- Forgetting that host networking bypasses Docker's isolation and port mapping
Best Answer (HR Friendly)
“A Docker network is a virtual network that lets containers talk to each other by name, similar to how computers on an office network can find each other. It also keeps unrelated groups of containers separated for security, so only the ones that are supposed to communicate can do so.”
Code Example
# Create an isolated bridge network
docker network create app-net
# Run two containers attached to it
docker run -d --name db --network app-net postgres:16
docker run -d --name api --network app-net myapp:latest
# From inside 'api', 'db' resolves by name via Docker's embedded DNS
docker exec api ping -c 1 db
# List networks and inspect one
docker network ls
docker network inspect app-netFollow-up Questions
- What is the difference between bridge, host, and overlay network drivers?
- How does Docker's embedded DNS resolve container names?
- When would you use an overlay network instead of a bridge network?
- How do you connect a running container to an additional network?
- What is the difference between the default bridge and a user-defined bridge?
MCQ Practice
1. What does a Docker network primarily provide to containers?
A Docker network lets containers discover each other by name and controls which containers can communicate.
2. Which built-in driver shares the host's network stack directly?
The host driver removes network isolation, letting the container use the host's network stack directly.
3. How do containers on the same user-defined bridge network typically find each other?
Docker runs an embedded DNS server so containers on the same user-defined network can resolve each other by name.
Flash Cards
What is a Docker network? — A virtual network letting containers communicate by name while isolating unrelated groups.
Name the four built-in Docker network drivers. — bridge, host, overlay, and none.
How do containers resolve each other by name? — Via Docker's embedded DNS server on user-defined networks.
Which driver is used for multi-host swarm communication? — The overlay driver.