停止docker容器的图像名称 - Ubuntu [英] Stopping docker containers by image name - Ubuntu

查看:193
本文介绍了停止docker容器的图像名称 - Ubuntu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ubuntu 14.04我正在寻找一种方法来停止运行容器,唯一的信息是在docker运行命令中使用的映像名称。



有没有命令可以找到与该映像名称匹配的所有匹配的运行容器并停止它们?

解决方案

按照问题8959 ,一个好的开始是:

  docker ps -a -q --filter =name =< containerName> 

由于名称是指容器而不是图像名称,需要使用 docker 1.9过滤器祖先 ://stackoverflow.com/users/158288/koekiebox> koekiebox 的回答

  docker ps -a -q --filter ancestor =< image-name> 






如下所述,由 kiril ,以删除这些容器:


stop 还返回容器。

所以链接停止 rm 将执行此工作:




  docker rm $(docker stop $( docker ps -a -q --filter ancestor =< image-name> --format ={{.ID}}))


On Ubuntu 14.04 I'm looking for a way to stop a running container and the only information I have is the image name that was used in the docker run command.

Is there a command to find all the matching running containers that match that image name and stop them?

解决方案

Following issue 8959, a good start would be:

docker ps -a -q --filter="name=<containerName>"

Since name refers to the container and not the image name, you would need to use the more recent docker 1.9 filter ancestor, mentioned in koekiebox's answer.

docker ps -a -q  --filter ancestor=<image-name>


As commented below by kiril, to remove those containers:

stop returns the containers as well.
So chaining stop and rm will do the job:

docker rm $(docker stop $(docker ps -a -q --filter ancestor=<image-name> --format="{{.ID}}"))

这篇关于停止docker容器的图像名称 - Ubuntu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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