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.

Really nothing worked!! This drives me nuts.

Docker compose down --remove-orphans doesn’t work. Bringing down all services and all containers and running docker system prune doesn’t work


Using docker inspect on the network I don’t see any containers (in fact ALL containers are down).

But still I get:


failed to remove network docker_xxx_network: Error response from daemon: error while removing network: network docker_xxx_network id 05245b263250edde24645a1c0f51b26d18591aab684fb73e7148c1d574b1493d has active endpoints

wth.

I really need to fully restart the server.

Down as in stopped, but existing? Or down as in removed and non-existing?

I had this problem and eventually found a solution.
I had obviously started some/all of the containers not using the compose file. I manually stopped each container and then removed it. Now I restarted the whole system using docker-compose up -d. after that point docker-compose down worked just fine

running

docker ps

showed me which container that depended on this needed to be down first

solved

Any way to debug this starting from the immediate error message - “has active endpoints”.
What is an “endpoint”? I would assume it’s a container
 but if docker network inspect shows “Containers”: {} then what is being enumerated to come to the conclusion that there are active endpoints?

This is an old issue originally about Docker Compose v1. It probably had a bug which caused what @meyay described

If you get the error message, that indeed means a container is still using that network, but eventually comose deletes it after getting the error message so you don’t see the container anymore. If you run it multiple times, and still get the error message, then you either had multiple networks and inspected the wrong one, or there is another bug somehwre. But in that case it is more likely you are still using Docker Compose v1 instead of v2.

Inspect the network using
docker network inspect {network_id}
Locate the container-id from response and then stop the container
docker stop {conatiner-id}

then you can do docker-compose down --remove-orphans