问题描述
docker-compose run
具有标志-rm
,可在运行后自动删除容器。我想知道是否有与docker-compose.yml对应的特定服务配置,因为我在yml中获得的其中一项服务是一次性构建过程,该过程应该只输出编译文件并自行消失。
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-compose中定义此行为。 yml
文件,我认为解释如下:
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:
code>图像已构建,并且服务的容器
已启动,然后可以使用 docker-compose停止
和 docker-compose start
来启动/停止服务。这与 docker-compose down
不同,
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:
您尝试执行的操作遇到了问题:
如果您 docker-compose up
和其中之一您的容器完成其任务并被(自动)移除,那么您就无法 docker-compose stop
和 docker-compose start
再次。删除的容器将不再存在,无法再次开始
。
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.
您可能想看看:
- docker-compose: option to automaticaly remove container after run in docker-compose.yml
- What is the difference between docker-compose up and docker-compose start?
这篇关于使用docker-compose.yml自动删除容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!