停止docker容器的图像名称 - Ubuntu [英] Stopping docker containers by image name - Ubuntu
问题描述
有没有命令可以找到与该映像名称匹配的所有匹配的运行容器并停止它们?
按照问题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 chainingstop
andrm
will do the job:
docker rm $(docker stop $(docker ps -a -q --filter ancestor=<image-name> --format="{{.ID}}"))
这篇关于停止docker容器的图像名称 - Ubuntu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!