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?"