What this error means
Docker refuses to remove a network while containers or tasks are still attached to it. The daemon reports:
Error response from daemon: network <name_or_id> has active endpoints
An "endpoint" is a container’s attachment to the network. Remove or detach all endpoints, then delete the network.
Quickstart
- List who’s using the network:
- docker ps --filter network=<network>
- docker network inspect <network>
- Stop/remove or disconnect containers:
- docker rm -f <container> OR
- docker network disconnect [-f] <network> <container>
- For Docker Compose: docker compose down -v
- For Swarm services: remove or detach the service from the network
- Finally: docker network rm <network>
Minimal working example
# 1) Reproduce the error
docker network create demo_net
docker run -d --name web --network demo_net nginx:alpine
# Fails because web is attached
docker network rm demo_net
# Error response from daemon: network demo_net has active endpoints
# 2) Fix
# Option A: disconnect then remove network
docker network disconnect demo_net web
docker network rm demo_net
# Option B: remove container(s) then remove network
docker rm -f web
docker network rm demo_net
Step-by-step resolution
- Identify the network and its attachments
- List networks:
- docker network ls
- Inspect attachments (shows Containers map):
- docker network inspect <network>
- Quick list of containers connected by name:
- docker ps --format '{{.ID}}\t{{.Names}}\t{{.Networks}}' | grep <network>
- Detach or remove connected containers
- Graceful stop and remove:
- docker stop <container> && docker rm <container>
- Hard remove if needed:
- docker rm -f <container>
- Detach without removing the container:
- docker network disconnect <network> <container>
- Add -f to disconnect even if the container is running
- Remove the network
- docker network rm <network>
- If the network is still reported as in use
- Containers might auto-restart and reattach. Temporarily disable restart policy:
- docker update --restart=no <container>
- Check for paused or dead containers still attached:
- docker ps -a --filter network=<network>
- Force disconnect any lingering endpoints you see in inspect:
- docker network disconnect -f <network> <container_id>
- If there are no containers but inspect still shows endpoints, restart Docker then retry:
- sudo systemctl restart docker
- docker network rm <network>
Docker Compose scenarios
Default Compose networks are named <project>_default unless overridden.
# compose.yaml
services:
app:
image: nginx:alpine
networks:
- webnet
networks:
webnet:
driver: bridge
Common fixes:
- Stop stack and remove networks:
- docker compose down -v
- Remove only the network (after containers are down):
- docker network rm <project>_webnet
- Identify Compose-managed networks:
- docker network ls --filter label=com.docker.compose.project=<project>
Swarm and overlay networks
Overlay networks are used by services and tasks. You cannot remove the network while any service references it.
- List services using a network (by name or ID):
- docker service ls
- docker service inspect <service> --format '{{json .Spec.TaskTemplate.Networks}}'
- Detach a network from a service:
- docker service update --network-rm <network> <service>
- Remove the service, then the network:
- docker service rm <service>
- docker network rm <network>
- If multiple services use the network, detach/remove each first.
Bulk cleanup
- Remove all unused networks not referenced by any container:
- docker network prune
- Add -f to skip confirmation in automated scripts
- Remove containers attached to a specific network, then the network:
- docker rm -f $(docker ps -aq --filter network=<network>)
- docker network rm <network>
Troubleshooting corner cases
- Default networks cannot be removed: bridge, host, none
- Stale endpoints after crashes:
- Restart the Docker daemon and try again
- If still stuck, ensure no containers or services reference the network across all nodes (in Swarm)
- Anonymous networks created by Compose for external links may persist until compose down -v is run
- Network names vs IDs:
- If names collide, prefer network ID in commands (from docker network ls)
Pitfalls
- Forcing disconnect on running workloads can drop live traffic
- Auto-restart policies can immediately reattach containers after you disconnect them
- Removing a network does not remove containers; they will fall back to remaining networks or lose connectivity
- In Swarm, you must detach the network from every service on every node; task churn can momentarily recreate attachments during rolling updates
Performance notes
- docker ps --filter network=<network> scales well compared to parsing full inspect output
- docker network prune scans networks and performs safety checks; avoid running it frequently on large hosts during peak load
- Removing large overlay networks in busy Swarm clusters can trigger control-plane work; prefer maintenance windows for bulk network changes
- Using targeted disconnect/remove commands is faster and safer than broad prune operations
Fast reference
- Show who is attached:
- docker ps --filter network=<network>
- docker network inspect <network>
- Disconnect a container:
- docker network disconnect [-f] <network> <container>
- Remove a network:
- docker network rm <network>
- Compose teardown:
- docker compose down -v
- Swarm detach:
- docker service update --network-rm <network> <service>
FAQ
Q: Why can’t I remove the bridge/host/none network? A: They are system networks created by Docker and cannot be removed.
Q: Does removing a network delete containers? A: No. It only removes the virtual network. Containers may lose connectivity.
Q: How do I quickly find containers using a network? A: docker ps --filter network=<network> or docker network inspect <network>.
Q: Can I disconnect a running container? A: Yes. Use docker network disconnect -f <network> <container>. Proceed carefully to avoid traffic loss.