In today’s post we are going to list a few solutions on how to deal with the following Docker network error: ERROR: error while removing network: network <> has active endpoints
.
There also few possible reasons behind it, starting from renaming docker-compose service before taking down the containers, having multiple networks with the same name, or even forgetting to include the docker-compose -p
env variable when taking down the stack.
Prerequisites
- Docker
- Docker Compose
- sudo privileges
Solution(s)
Solution 1. Try to restart the Docker service and remove the hanging network afterwards.
1. sudo systemctl restart docker
2. docker network rm bad-network
3. docker network prune
Solution 2. Take down the Docker Compose stack using the --remove-orphans
flag.
docker-compose down --remove-orphans
Solution 3. If you have already started the Docker Compose stack using the COMPOSE_PROJECT_NAME -p
env var, make sure to specify the same env var when taking down the stack.
docker-compose -p SOME_PROJECT_NAME down
Solution 4. Try to stop and remove the container(s) first, then disconnect and remove the network. For instance:
1. docker stop container1 && docker rm container1
2. docker network disconnect -f bad_network container1
3. docker network rm bad_network
4. docker-compose down
5. docker-compose up --remove-orphans
Conclusion
If you can think of any other alternative solution, please do let me know in the comment section below. On a side note, follow our official channel on Telegram.