使用docker-compose.yml自动删除容器 [英] Auto remove container with docker-compose.yml

查看:1133
本文介绍了使用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 文件,我认为解释如下:

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:


docker-compose up 构建,(重新)创建,启动并附加到用于服务的容器。

docker-compose up builds, (re)creates, starts, and attaches to containers for a service.

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:


停止容器并删除容器,网络,卷和图像由 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: 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自动删除容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆