docker-compose run
has a flag --rm
that auto removes the container after run. I am wondering if theres an equivalent config with docker-compose.yml for a specific service, as one of which services i got in yml is a one off build process which should just output the compile file and disappear itself.
Stops containers and removes containers, networks, volumes, and images created by up .
If you know when you're creating a container that you won't want to keep it around once you're done, you can run docker run --rm to automatically delete it when it exits: Run and Remove: docker run --rm image_name.
Removes stopped service containers. By default, anonymous volumes attached to containers are not removed.
Stop the application containers using docker-compose stop: Remove the application containers using docker-compose rm -f: Note: If you don’t specify -f in the above command, it will prompt you for Y/N before removing it.
It's not part of the Dockerfile or docker-compose.yml spec, it is only a cli option for the run command, so the answer is no. You will need to rely on something external for enforcing. If you got some build tool for your project it is usually best to wrap docker-compose tasks with that.
When you’re ready to tear it all down, simply run docker-compose down or hit the trash can on the Docker Dashboard for the entire app. The containers will stop and the network will be removed. By default, named volumes in your compose file are NOT removed when running docker-compose down.
# docker-compose rm -v You can also remove a specific container by specifying the container name. The following will remove only the data container. # docker-compose rm -f data Going to remove data Removing data... done
I haven't found any option to help you define this behavior in the docker-compose.yml
file and I think the explanation is the that it will break how some of the docker-compose ...
commands are supposed to work.
More on this up
/down
, start
/stop
thing:
docker-compose up
builds, (re)creates, starts, and attaches to containers for a service.
Since your images
are built and the containers
of your service have started, you can then use docker-compose stop
and docker-compose start
to start/stop your service. This is different from docker-compose down
which:
Stops containers and removes containers, networks, volumes, and images created by
up
.
Problem with what you are trying to do:
If you docker-compose up
and one of your containers finishes its task and gets (auto)removed, then you can't docker-compose stop
and docker-compose start
again. The removed container will not be there to start
it again.
You might want to take a look at:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With