Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

docker compose down leaves the default network behind

ErrorNetwork myproject_default Resource is still in use

Short 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.

  • Applies to Docker Engine 28, Docker Compose 2.3x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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}}'
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2The 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. 3The network is under networks: with external: true and still exists after downThe network is declared external, so down never removes itFix

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-orphans

3Verify

The network no longer appears in the list.

docker network ls --filter name=myproject_default

Confirmed by docs.docker.com

Did this fix it?

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_default

2Fix

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 down

3Verify

Run down again. The warning is gone and the network is removed.

docker network ls --filter name=myproject_default

Confirmed by docs.docker.com

Did this fix it?

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.yml

2Fix

This is documented behaviour, not a fault. Remove the network yourself once nothing uses it.

docker network rm shared-net

3Verify

The network is gone from the list.

docker network ls

Confirmed by docs.docker.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.