使用 docker-compose.yml 自动移除容器 [英] Auto remove container with docker-compose.yml
问题描述
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
文件中定义此行为,我认为解释是它会破坏某些 docker-compose ...
命令的工作方式.
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.
更多关于这个 up
/down
,start
/stop
的事情:
More on this up
/down
, start
/stop
thing:
docker-compose up
为服务构建、(重新)创建、启动和附加到容器.
docker-compose up
builds, (re)creates, starts, and attaches to containers for a service.
既然您的 images
已构建并且服务的 containers
已启动,您就可以使用 docker-compose stop
和 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:
停止容器并删除由 up
创建的容器、网络、卷和图像.
Stops containers and removes containers, networks, volumes, and images created by
up
.
您尝试执行的操作有问题:
如果你 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.yml 自动移除容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!