docker compose down leaves the default network behind
Network myproject_default Resource is still in useShort answer
Compose only removes a project network when no container is attached to it. If one still is, down prints a warning and leaves the network. Inspect the network to see who holds it, then remove those containers with --remove-orphans, disconnect them by hand, or accept that external networks are never removed.
Fix it fast
1Find out which cause you have
Ask the daemon which containers are still attached to the network named in the message. The names in the output decide which cause below applies.
docker network inspect myproject_default --format '{{range .Containers}}{{.Name}}{{"\n"}}{{end}}'2Match what you see, then jump to its fix
- 1
The attached container carries the project name but its service was renamed or deleted from docker-compose.ymlA container from the same project is no longer in the Compose fileFix - 2
The container in the inspect output was created with docker run --network, or by another Compose project that joined this networkA container started outside this Compose project is attachedFix - 3
The network is under networks: with external: true and still exists after downThe network is declared external, so down never removes itFix
- 1
What does the error look like?
Network myproject_default Resource is still in use
Cause 1 of 3
A container from the same project is no longer in the Compose file
1Check
Compose treats containers of the project that match no current service as orphans. A plain down does not remove them, so they keep the network in use.
docker compose ps --all
docker ps -a --filter "label=com.docker.compose.project=myproject"2Fix
Run down with the orphan flag. The docs describe it as removing containers for services not defined in the Compose file.
docker compose down --remove-orphans3Verify
The network no longer appears in the list.
docker network ls --filter name=myproject_defaultConfirmed by docs.docker.com
Cause 2 of 3
A container started outside this Compose project is attached
1Check
Compose only stops what it created. The network inspect output lists every attached container, whoever started it.
docker network inspect myproject_default2Fix
Stop that container, or detach it from the network. Docker states that a network can only be removed after the containers connected to it are disconnected.
docker network disconnect myproject_default other-container
docker compose down3Verify
Run down again. The warning is gone and the network is removed.
docker network ls --filter name=myproject_defaultConfirmed by docs.docker.com
Cause 3 of 3
The network is declared external, so down never removes it
1Check
Look for external in the Compose file.
grep -n -B2 -A2 "external" docker-compose.yml2Fix
This is documented behaviour, not a fault. Remove the network yourself once nothing uses it.
docker network rm shared-net3Verify
The network is gone from the list.
docker network lsConfirmed by docs.docker.com
How do I stop it coming back?
- After renaming or deleting a service, run docker compose up -d --remove-orphans once.
- Give containers started by hand a name and stop them before tearing the project down.
- Keep shared networks external on purpose and document who creates and removes them.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Docker says the network you named does not exist
Error response from daemon: network myapp not found
A container or Compose file refers to a network name the daemon does not have.
3 causes, each with a fixServers
Docker Compose warns about orphan containers for the project
Compose displays a warning about orphaned containers
Compose found containers carrying your project's label whose service is no longer in the Compose file.
3 causes, each with a fixServers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fix