Docker compose project down specific containers

Hello All ,

I’m using docker for development and use devcontainers with VSCode, Currently have a Container for development and 4x app containers that launch during test runs.

Devcontainer uses the file docker-compose.workspace.yml for the container, which adds it to the project myapp-devcontainer

I then have another docker-compose.yml which is run by my nox script

docker compose --project-name myapp-devcontainer -f docker-compose.yml up -d

At the end of the test, I want to have all the containers in docker-compose.yml to go down so I did

docker compose --project-name myapp-devcontainer -f docker-compose.yml down

but this also shuts down the docker-compose.workspace.yml container (which I assume is due to the “project” being supplied)

Is there a way that I can stop all the containers in docker-compose.yml that are part of the project, without downing the whole project?

docker compose down would not remove your devcontainer unless its name also listed in docker-compose.yml and part of the same compose project. Do you have service like that in docker-compose.yml?

✗ docker compose --project-name myapp_devcontainer -f .devcontainer/docker-compose.yml up -d
[+] Running 4/0
 ⠿ Container cont1   Running   0.0s
 ⠿ Container cont2   Running 0.0s
 ⠿ Container cont3  Running 0.0s
 ⠿ Container cont4   Running 0.0s
✗ docker compose --project-name myapp_devcontainer -f .devcontainer/docker-compose.yml down 
[+] Running 4/5
 ⠙ Container workspace  Stopping    10.2s
 ⠿ Container cont1     Removed        6.0s
 ⠿ Container cont2    Removed        5.8s
 ⠿ Container cont3     Removed        5.5s
 ⠿ Container cont4    Removed          5.6s

As you can see, when i do the UP command it doesnt mention the “workspace” container but when i run the DOWN it does remove it. It is not mentioned at all in the docker-compose.yml which is why I couldn’t understand why it removes it.

That is indeed unexpected. I don’t know if it is intentional or not. You could try to report it in the compose repository on GitHub