Error while removing network: network ... has active endpoints

I have a system with several docker-compose containers and networks. Occasionally, when we do a docker-compose down, it fails with the error:
ERROR: error while removing network: network broker_net-conquest id 94bc69b11c077471717c2d2ab457d5e4010086ba80ad528cc4cc03772bc1da37 has active endpoints
But, if I try to find the container with the active endpoint, there are none:

# docker inspect broker_net-conquest [ { "Name": "broker_net-conquest", "Id": "94bc69b11c077471717c2d2ab457d5e4010086ba80ad528cc4cc03772bc1da37", "Created": "2021-05-14T19:12:16.253503798Z", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.27.0.0/16", "Gateway": "172.27.0.1" } ] }, "Internal": false, "Attachable": true, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, **"Containers": {},** "Options": {}, "Labels": { "com.docker.compose.network": "net-conquest", "com.docker.compose.project": "broker", "com.docker.compose.version": "1.28.6" } } ]

In fact, there are no containers running:

# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

To get out of this state, we need to restart the docker service. Not something we really want to do in a production system.

Any ideas?

2 Likes

adding --remove-orphans worked for me. The docker-compose file might have changed since you created the first set of containers/network

1 Like

I’ve taken over this issue. I’ve run docker-compose down --remove-orphans and that has not resolved the issue. Still seeing the following error:

ERROR: error while removing network: network broker_net-conquest id 1b6a38f8fda17d1412a7445e1b8bbcf7c4495fb62874c686f852378ffbf7fb07 has active endpoints

Not sure how to resolve this.

Just had this happen also. Even restarting docker service didn’t fix it.
Had to restart the OS.

Has anyone run into this recently ? Apart from restarting docker daemon and deleting the network I did not find any solution ? What if in the scenarios where docker daemon cannot be restarted how to fix this ?

1 Like

I had the same issue and apparently it was caused by changes in the docker-compose file which I made after docker compose up command, when I changed it back to the original state docker compose down worked fine.

This stackoverflow response helped me!

I had an endpoint, so docker network disconnect -f <network> <endpoint> worked for me, but other folks without endpoints suggested that docker system prune helped.

2 Likes

Looks like a race condition, where it tries to remove the network, before all containers attached to it are removed. Eventually all resources in the compose project should be removed, so it should be rather a cosmetic problem. Though,

If the above problem creates a problem in a script, you can make it wait until all resources are actually removed

PROJECT="$(basename $PWD)"
for resource_type in container network; do
  until [ -z "$(docker $resource_type ls --filter label=com.docker.compose.project="${PROJECT}" -q)" ]; do
    sleep 1
  done
done

Note: the snippet either needs to be executed in the folder where the compose file is stored, or if a project name is provided through parameters, it needs to be set instead.

Though, the only use case where it might make sense to me is if you want to run docker compose down followed by a docker compose up -d in a script or pipeline.