While running docker compose down on a docker compose stack, I came across this error:

network has active endpoints

Now if I listed the docker networks with:

docker network ls

I could see the offending network listed:

NETWORK ID     NAME                           DRIVER    SCOPE
2222a222222a   <OFFENDING NETWORK NAME>       bridge    local

Now I could probably fix this by removing the offending network with:

docker network rm <OFFENDING NETWORK NAME>

A quick Google pointed me in the right direction to get things working as expected. The network I was trying to remove was being used by an orphaned container.

Running the following fixed the issue:

docker compose down --remove-orphans

This can occur if you run docker run or equivalent without the --rm parameter, where container is not removed after the command exits.