Default bridge network versus user‑defined bridge network for managing Docker IP address exhaustion
0 reputation · 19 Mar 2025, 07:44 UTC
0 reputation · 19 Mar 2025, 07:44 UTC
Goal: Decide whether to rely on Docker’s automatically created default bridge network or to create a user‑defined bridge network with a custom subnet in order to control the risk of IPv4 address exhaustion in environments with high container churn.
Constraint: The default bridge uses a fixed 172.17.0.0/16 subnet (~65 000 addresses) and does not reclaim IPs from stopped containers until they are removed with docker rm or the --rm flag. A user‑defined bridge lets the operator specify any subnet size (e.g., /20) and enables IP address reuse after container removal, but changing that subnet later requires deleting and recreating the network, which disconnects running containers.
Uncertainty: Teams must weigh the operational simplicity of the default bridge against the administrative overhead of managing custom networks and the need to recreate them when subnet adjustments are needed.
Which approach offers a better trade‑off between ease of use and exhaustion mitigation for a CI pipeline that launches thousands of short‑lived containers daily? Does the ability to choose a smaller subnet in a user‑defined bridge justify the extra step of deleting and recreating the network when the subnet size must be changed? How does automatic IP address reuse upon container removal compare to manual docker rm in preventing gradual address pool depletion?
32275 reputation · 19 Mar 2025, 16:45 UTC
For a CI pipeline that launches thousands of short‑lived containers each day, creating a user‑defined bridge network with a subnet sized to hold the peak concurrent container count is the preferred approach because it lets you control the IP pool size and enables automatic reuse of addresses after containers are removed, whereas the default bridge’s fixed /16 pool cannot be resized and retains IPs until containers are explicitly deleted.
The default bridge (docker0) uses a fixed 172.17.0.0/16 subnet (~65 000 addresses) and does not reclaim an IP from a stopped container until the container is removed with docker rm or the --rm flag. A user‑defined bridge lets you specify any subnet via --subnet, and Docker’s IPAM reallocates freed addresses immediately after a container disappears, but changing the subnet later requires deleting and recreating the network, which disconnects any running containers.
10.0.0.0/16 for ~65 k addresses, or a larger block if you expect more).docker network create --subnet 10.0.0.0/16 ci-bridge
docker run --rm --network ci-bridge …
docker network inspect ci-bridgeand check the
IPAM.Config and Containers sections.docker network rm ci-bridge), then recreate it with a larger subnet and reconnect the running containers.To size the subnet accurately, please confirm the typical peak number of concurrently running containers in your CI jobs (or the observed IP exhaustion rate).
Use comments to ask for clarification. Post a solution as an answer.
4,810 reputation · 19 Mar 2025, 19:15 UTC
One clarification worth adding to the answer above: on both network types, IP reuse happens when the container object is removed, not when it stops. The user-defined bridge doesn't reclaim addresses any faster than the default bridge — the difference is that the default bridge's fixed /16 hides leaks longer, while a deliberately smaller subnet makes leaked containers surface quickly as allocation failures. That can actually be an argument for a tighter subnet in CI: it turns silent container leakage into a loud, debuggable error.
So the practical pairing is: user-defined bridge sized to peak concurrency plus headroom, --rm on every CI container, and a periodic docker system prune (or a CI janitor job) to catch containers orphaned by crashed jobs. Verify reuse behavior directly with docker network inspect before and after a removal — if freed IPs aren't being reassigned, the leak is in your cleanup path, not the network config.