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.
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
- How to reload apache in php-apache docker containe
I'm not sure I understand, docker-compose run --user is an option, and the docker-compose.yml supports the user key (http://docs.docker.com/compose/yml/#working95dir-entrypoint-user-hostname-domainname-mem95limit-privileged-restart-stdin95open-tty-cpu95shares).
Simply run
docker-compose up && docker-compose rm -fsv
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 following:Since your
images
are built and thecontainers
of your service have started, you can then usedocker-compose stop
anddocker-compose start
to start/stop your service. This is different fromdocker-compose down
which: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'tdocker-compose stop
anddocker-compose start
again. The removed container will not be there tostart
it again.You might want to take a look at:
My solution to this was to create a little bash script that automatically removes containers afterwards - It doesn't work with detached mode, but I suppose that might not be such a big issue.
If you're on macOS, you can put this script in
usr/local/bin
. Assuming it's namedd-c
, you can then runchmod +x usr/local/bin/d-c
to make it executable. On Windows, I have no idea how to get this working, but on Linux it should be similar.Edit:
I've updated my script so that detached mode will work normally: