6.1.4.4 Removal Network Detachment
A focused guide to Removal Network Detachment, connecting core concepts with practical Docker and container operations.
Removal network detachment is the step where a container, upon being removed, is automatically disconnected from any Docker networks it was attached to, freeing up its reserved network resources (such as its assigned IP address) within those networks for reuse by other containers.
What Happens Automatically During Removal
A container's network attachments are cleaned up as part of its removal, without requiring any separate, explicit detachment step.
docker network create mynet
docker run -d --name myapp --network mynet myapp:1.0
docker rm -f myapp
docker network inspect mynet --format '{{json .Containers}}'
After removal, myapp no longer appears among mynet's connected containers, confirming the automatic detachment.
Why This Detachment Matters for Resource Reuse
Without this automatic cleanup, a removed container's reserved network resources — its assigned IP address within a given network — could remain unavailable indefinitely, eventually exhausting a network's available address space if many containers were created and removed without proper cleanup.
docker run -d --name myapp-1 --network mynet myapp:1.0
docker rm -f myapp-1
docker run -d --name myapp-2 --network mynet myapp:1.0
The second container can be assigned an IP address within mynet without issue, since the first container's removal properly freed up its previously reserved address.
Detaching From a Network Without Removing the Container
A still-running container can also be explicitly detached from a specific network without being removed entirely, useful for reconfiguring its networking without recreating it.
docker network disconnect mynet myapp
Why Removal Network Detachment Matters
This automatic cleanup ensures that Docker's networking resources are correctly reclaimed as containers are removed, preventing a gradual, easily overlooked accumulation of stale network reservations that could otherwise affect a network's capacity over time.