docker compose down finishes, yet some containers are still there
Your error
docker compose down returns at once, but docker ps still lists the stack's containers1 more line it can showFix it fast
Most common cause, 1 of 3down runs under a different project name than up did
Run down with the project name the stack really has, then pin one name in the file so every command agrees.
docker compose -p shop-api down
# compose.yaml
name: shop-apiShort answer
docker compose down removes only the containers of services that the current project and its active profiles define. Containers survive when down runs under another project name (other folder, -p or COMPOSE_PROJECT_NAME), when their service sits in a profile you did not pass, or when the service left the file. Match the project, add --profile, or use --remove-orphans.
Which cause do you have?
From the folder you ran down in, compare what this project sees with what Docker runs. A container that docker ps shows but docker compose ps does not belongs to another project, another profile or a removed service.
docker compose ls --all
docker compose ps --all
docker ps --format '{{.Names}}'Then find the line you see in this list and open its fix:
- 1down runs under a different project name than up did
docker compose ps --all is empty here, while docker compose ls --all lists a running project under another name - 2The leftover service belongs to a profile that down was not given
The container that stays up comes from a service with a profiles: key, started earlier with --profile or COMPOSE_PROFILES - 3The service was renamed or deleted from the Compose file
The surviving container was created for a service that docker compose config --services no longer lists
What does the error look like?
docker compose down returns at once, but docker ps still lists the stack's containersOne service of the stack, such as an admin or debug tool, keeps running after docker compose down
Cause 1 of 3
down runs under a different project name than up did
You seedocker compose ps --all is empty here, while docker compose ls --all lists a running project under another name
Check
Compose keeps projects apart by name, and docker compose down only touches the project it resolves. That name comes from -p first, then COMPOSE_PROJECT_NAME, then the top-level name: attribute, then the base name of the folder holding the Compose file. Starting the stack with -p, from a copy of the folder, or with the variable set, and stopping it without them, points down at an empty project.
grep -n '^name:' compose.yaml
echo "COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}"
docker compose ls --allFix
Run down with the project name the stack really has, then pin one name in the file so every command agrees.
docker compose -p shop-api down
# compose.yaml
name: shop-apiVerify
docker compose ls --all no longer lists the project, and docker ps shows none of its containers.
docker compose ls --allConfirmed by docs.docker.com
Cause 2 of 3
The leftover service belongs to a profile that down was not given
You seeThe container that stays up comes from a service with a profiles: key, started earlier with --profile or COMPOSE_PROFILES
Check
Services without a profiles attribute are always enabled, but a service assigned to a profile is included only when that profile is active. So a plain docker compose down stops the unprofiled services and leaves running whatever you started with --profile debug.
grep -n -B3 'profiles:' compose.yamlFix
Pass the same profile to down that you passed to up, either as a flag or through the environment variable.
docker compose --profile debug down
# or
COMPOSE_PROFILES=debug docker compose downVerify
docker compose ps --all with the same profile lists nothing.
docker compose --profile debug ps --allConfirmed by docs.docker.com
Cause 3 of 3
The service was renamed or deleted from the Compose file
You seeThe surviving container was created for a service that docker compose config --services no longer lists
Check
By default down removes containers for the services the file defines now. A container created for a service you later renamed or deleted is no longer one of them, so it outlives every plain down.
docker compose config --services
docker ps --format '{{.Names}}'Fix
Ask down to take the leftover containers with it.
docker compose down --remove-orphansVerify
docker ps no longer shows the leftover container.
docker ps --format '{{.Names}}'Confirmed by docs.docker.com
How do I stop it coming back?
- Put a top-level name: in every Compose file, so the folder name, -p and COMPOSE_PROJECT_NAME cannot make up and down disagree.
- Set COMPOSE_PROFILES once for the whole deploy script, so up and down always see the same profiles instead of one command getting --profile and the other not.
- Run docker compose down --remove-orphans in deploy scripts after any change that renames or drops a service.
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 on the same stack: TaxiDex, Dispatch Pro.