Bridge network default behavior in Docker - Time & Space Complexity
We want to understand how Docker's bridge network handles container connections as more containers join.
How does the work Docker does grow when more containers connect to the default bridge network?
Analyze the time complexity of Docker managing container connections on the default bridge network.
docker network create my-bridge
for i in $(seq 1 5); do
docker run -d --net=my-bridge --name container$i alpine sleep 1000
if [ $i -gt 1 ]; then
docker exec container$i ping -c 1 container$((i-1))
fi
done
This code creates a bridge network, then starts 5 containers connected to it, each pinging the previous container.
Look for repeated actions that affect performance.
- Primary operation: Docker updates network routing and address tables for each new container joining the bridge.
- How many times: Once per container added to the network.
As more containers join, Docker updates network info for each one.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 updates to routing and address tables |
| 100 | About 100 updates |
| 1000 | About 1000 updates |
Pattern observation: The work grows directly with the number of containers added.
Time Complexity: O(n)
This means the work Docker does grows in a straight line as more containers join the bridge network.
[X] Wrong: "Adding more containers does not affect network setup time because Docker handles it instantly."
[OK] Correct: Each new container requires Docker to update network settings, so the time grows with the number of containers.
Understanding how Docker manages network connections helps you explain container scaling and network setup in real projects.
"What if Docker used a different network driver that caches routing info? How would that change the time complexity?"
Practice
Solution
Step 1: Understand bridge network basics
The default bridge network connects containers on the same Docker host and allows communication by IP address.Step 2: Analyze name resolution behavior
By default, containers on the bridge network cannot resolve each other's names without a custom network.Final Answer:
Containers can communicate with each other by IP address only. -> Option CQuick Check:
Bridge network communication = IP only [OK]
- Assuming container names resolve by default
- Thinking containers share host network directly
- Believing containers cannot communicate at all
Solution
Step 1: Identify command to inspect networks
To see details of a specific network, usedocker network inspect <network-name>.Step 2: Apply to default bridge network
The default bridge network is named "bridge", so the command isdocker network inspect bridge.Final Answer:
docker network inspect bridge -> Option DQuick Check:
Inspect bridge network = docker network inspect bridge [OK]
- Using 'docker container ls' to see networks
- Trying 'docker info bridge' which is invalid
- Confusing 'docker network ls' with inspect
Solution
Step 1: Recall default bridge network name resolution
The default bridge network does not provide automatic DNS resolution for container names.Step 2: Understand ping behavior by name
Trying to ping by container name will fail because the name cannot be resolved to an IP address.Final Answer:
Ping fails because default bridge does not support container name resolution. -> Option AQuick Check:
Default bridge name resolution = no [OK]
- Assuming ping by name works by default
- Confusing image sharing with network name resolution
- Thinking custom networks are not needed
Solution
Step 1: Understand default bridge limitations
Default bridge network does not support container name resolution for communication.Step 2: Identify solution for name-based communication
Creating a user-defined bridge network enables automatic DNS resolution of container names.Final Answer:
You forgot to create a user-defined bridge network. -> Option BQuick Check:
Name resolution needs user-defined bridge [OK]
- Blaming container state without checking network
- Assuming Docker daemon is stopped without evidence
- Ignoring network type for name resolution
Solution
Step 1: Identify network supporting name resolution and NAT
User-defined bridge networks provide automatic DNS for container names and NAT for internet access.Step 2: Evaluate other options
Default bridge lacks name resolution; host network shares host IP but no DNS; macvlan isolates containers and does not provide NAT by default.Final Answer:
Connect both containers to a user-defined bridge network which supports name resolution and NAT for internet access. -> Option AQuick Check:
User-defined bridge = name resolution + NAT [OK]
- Editing /etc/hosts manually is error-prone
- Assuming host network provides container DNS
- Using macvlan without NAT causes no internet
Ready to prove it?
Pass the test and this pattern moves unknown
