compose icon indicating copy to clipboard operation
compose copied to clipboard

Support autoremoval of docker-compose containers

Open mipo256 opened this issue 2 years ago • 3 comments

Description

I didn't manage to find this issue, so I create a feature request: It would be great if you have an --rm flag similar to what we have in docker.

There is a question about it on SO that is quite popular, and it seems that this feature concerns not only me. What I think will be great, is if I would have the ability to do smth like:

docker-compose --rm up

And then, once the containers (or single container) are stopped, they automatically get removed. Sometimes you need to test something, and you relaunch containers multiple times, and it is quite tedious to remove them again and again. I know we can use

docker-compose rm -fsv

but it is still an additional command. Would be great if there will be a build-in option.

mipo256 avatar Jun 10 '23 07:06 mipo256

This flag is available on docker compose run. compose up serves a distinct purpose, and typically relies on previous container to inherit anonymous volumes, and will recreate container if needed, or will just restart container.

Can you please clarify your use-case ? "Sometimes you need to test something, and you relaunch containers multiple times" - right, but why would you remove the container as you relaunch, while compose up does manage this for you?

ndeloof avatar Jun 12 '23 08:06 ndeloof

Yes, but docker-compose accepts only one service to run AFIAK. The docker-compose run is a pretty good approach, but I have 3 external components needed to perform E2E test. It seems I can work around this with depends_on, but that is kind of a hack since my rabbitmq is not really somehow dependent on postgres container.

mipo256 avatar Jun 12 '23 08:06 mipo256

Your should indeed run e2e test using docker compose run and use depends_on to make it explicit the service being required for the test to run.

We also could expose the AutoRemote attribute in compose.yaml, as this is an engine API parameter

ndeloof avatar Jun 12 '23 08:06 ndeloof

closing as obsolete. If you encounter a comparable issue, please create a fresh new one with details on your environment

ndeloof avatar Oct 23 '24 06:10 ndeloof