Fix: Docker error: network has active endpoints
Quick Answer
How to fix Docker 'network has active endpoints' error when removing networks, caused by running containers, stale endpoints, orphaned compose networks, and failed cleanups.
The Error
You try to remove a Docker network and get:
Error response from daemon: error while removing network: network my-network id abc123def456
has active endpointsOr:
error: failed to remove network: network my-network has active endpointsOr during docker-compose down:
ERROR: error while removing network: network my-project_default has active endpointsDocker refuses to remove the network because one or more containers are still connected to it. Docker networks cannot be deleted while any container — running or stopped — is attached.
Why This Happens
Docker networks are reference-counted. Every container connected to a network holds a reference. When you try to delete the network, Docker checks for active endpoints (container connections). If any exist, the deletion fails.
Common causes:
- Containers are still running. You forgot to stop containers before removing the network.
- Stopped containers still attached. Stopped containers maintain their network attachment until they are removed.
- Orphaned endpoints. A container was forcefully killed or Docker crashed, leaving stale network endpoints.
- Docker Compose stale state. A previous
docker-compose upcreated the network, but the compose file changed anddocker-compose downcannot clean up properly. - Multi-compose projects sharing a network. Multiple Compose projects share an external network, and one project’s containers are still attached.
Fix 1: Find and Stop Connected Containers
Identify which containers are using the network:
docker network inspect my-network --format '{{range .Containers}}{{.Name}} {{end}}'Or for detailed information:
docker network inspect my-networkLook at the Containers section in the JSON output. It lists every container connected to the network.
Stop and remove the containers:
docker stop container1 container2
docker rm container1 container2Then remove the network:
docker network rm my-networkPro Tip: Use
docker network inspectwithjqfor cleaner output:docker network inspect my-network | jq '.[0].Containers | keys[]'This lists only the container IDs, which you can pipe to
docker stopanddocker rm.
Fix 2: Disconnect Containers from the Network
If you do not want to stop the containers but just want to free the network, disconnect them first:
docker network disconnect my-network container1
docker network disconnect my-network container2Then remove the network:
docker network rm my-networkForce disconnect if a normal disconnect fails (e.g., the container no longer exists):
docker network disconnect -f my-network container1The -f flag forces disconnection even if the container is not running or has been removed.
Fix 3: Fix Stale Endpoints
Sometimes Docker reports active endpoints even though no containers are visibly connected. This happens after crashes, forced kills, or Docker daemon restarts.
Check for ghost containers:
docker network inspect my-networkIf the Containers section lists containers that docker ps -a does not show, you have stale endpoints.
Fix: Force disconnect the stale endpoint:
docker network disconnect -f my-network <container-id-from-inspect>Use the container ID shown in the network inspect output, even if the container no longer exists.
Fix: Restart the Docker daemon:
sudo systemctl restart dockerA daemon restart cleans up stale network state. Warning: This stops all running containers briefly. They restart if they have a restart policy.
If the Docker daemon itself is not running, see Fix: Docker daemon is not running.
Fix 4: Fix Docker Compose Network Issues
Docker Compose creates a default network named <project>_default for each project. Common issues:
Orphaned containers from a previous run:
docker-compose down --remove-orphansThe --remove-orphans flag removes containers from services that are no longer defined in the compose file.
If docker-compose down itself fails:
# Stop all containers in the project
docker-compose stop
# Remove containers
docker-compose rm -f
# Now remove the network manually
docker network rm my-project_defaultIf the compose file was renamed or moved:
Docker Compose uses the directory name as the project name. If you moved the compose file, the project name changed and docker-compose down cannot find the old containers.
# Specify the old project name explicitly
docker-compose -p old-project-name downCommon Mistake: Running
docker-compose downfrom a different directory than where you randocker-compose up. The project name is derived from the directory name, sodownlooks for containers under the wrong project name and cannot find or stop them.
Fix 5: Handle External Shared Networks
When multiple Compose projects share an external network, you cannot remove it until all projects disconnect:
# compose-project-a.yml
networks:
shared:
external: true
name: my-shared-network# compose-project-b.yml
networks:
shared:
external: true
name: my-shared-networkFind all containers on the shared network:
docker network inspect my-shared-network --format '{{range .Containers}}{{.Name}} ({{.IPv4Address}}){{"\n"}}{{end}}'Stop all projects using the network:
cd project-a && docker-compose down
cd project-b && docker-compose downThen remove the network:
docker network rm my-shared-networkFix 6: Prune Unused Networks
If you have many unused networks and want to clean them all up:
docker network pruneThis removes all networks not used by at least one container. Docker asks for confirmation first.
Skip the confirmation prompt:
docker network prune -fPrune networks older than a certain age:
docker network prune --filter "until=24h"This removes networks created more than 24 hours ago that are not in use.
Full system cleanup (networks, containers, images, volumes):
docker system prune -aWarning: docker system prune -a removes everything not currently in use — all stopped containers, all unused images, all unused networks, and all build cache. It does not remove volumes unless you add --volumes. Use with caution. For disk space issues, see Fix: Docker no space left on device.
Fix 7: Fix Network Issues After Docker Upgrade
After upgrading Docker, the network subsystem might have stale state from the old version:
# Check for inconsistencies
docker network ls
docker network inspect bridge
# Restart Docker to reinitialize networking
sudo systemctl restart dockerIf specific networks are corrupted, remove and recreate them:
docker network rm my-network
docker network create my-networkFor custom networks with specific subnets:
docker network create --subnet=172.20.0.0/16 --gateway=172.20.0.1 my-networkFix 8: Handle Swarm Mode Networks
In Docker Swarm mode, networks behave differently. Service networks cannot be removed while services use them:
# Check which services use the network
docker service ls --filter "network=my-overlay-network"
# Remove the services first
docker service rm my-service
# Then remove the network
docker network rm my-overlay-networkForce remove a stuck Swarm network:
docker network rm my-overlay-networkIf this fails, leave and rejoin the swarm:
docker swarm leave --force
docker swarm initWarning: Leaving the swarm stops all services and removes all swarm state. Only do this as a last resort.
If Docker containers are having port conflicts instead of network issues, see Fix: Docker port is already allocated.
Still Not Working?
If the network still reports active endpoints after trying all fixes:
Check for containers in other namespaces. Docker Desktop on macOS/Windows uses a VM. Containers might be running inside the VM that are not visible from docker ps:
docker ps -a --format "{{.ID}} {{.Names}} {{.Status}}" | grep -i exitCheck for Kubernetes-managed containers. If Docker Desktop has Kubernetes enabled, Kubernetes creates its own networks and containers. These might hold references to your networks:
docker ps -a | grep k8sDo not remove Kubernetes-managed containers or networks manually.
Check for Docker daemon bugs. Some Docker versions have bugs where network endpoints are not cleaned up properly. Update Docker:
sudo apt update && sudo apt install docker-ce docker-ce-cli containerd.ioCheck iptables rules. Docker manages iptables rules for networking. Corrupted rules can interfere with network operations:
sudo iptables -L -n | grep -i dockerLast resort — reset Docker networking entirely:
sudo systemctl stop docker
sudo rm -rf /var/lib/docker/network
sudo systemctl start dockerThis deletes all Docker network state and forces Docker to recreate it from scratch. All custom networks are lost. Only use this if nothing else works.
For container permission issues that might be related to network configuration, see Fix: Docker permission denied socket.
Solo developer based in Japan. Every solution is cross-referenced with official documentation and tested before publishing.
Was this article helpful?
Related Articles
Fix: Docker Error: Bind for 0.0.0.0:PORT failed: port is already allocated
How to fix Docker port is already allocated error by finding processes using the port, removing stopped containers, changing port mappings, and resolving Docker Compose port conflicts.
Fix: Docker container health status unhealthy
How to fix Docker container health check failing with unhealthy status, including HEALTHCHECK syntax, timing issues, missing curl/wget, endpoint problems, and Compose healthcheck configuration.
Fix: Docker build sending large build context / slow Docker build
How to fix Docker build sending large build context caused by missing .dockerignore, node_modules in context, large files, and inefficient Dockerfile layers.
Fix: Docker Build Cache Not Working - No Cache Being Used
How to fix Docker build cache not working when layers rebuild every time despite no changes, including layer ordering, .dockerignore, COPY invalidation, BuildKit cache mounts, and CI/CD cache strategies.