如何删除创建正在运行的容器的Docker映像?

时间:2019-06-20 14:52:40

标签: docker docker-swarm

我要删除这两张图片

dockersamples/visualizer                <none>              8dbf7c60cf88        22 months ago       148MB
dockersamples/examplevotingapp_result   <none>              e10df791f13c        2 years ago         227MB

我尝试了一切,问题是当我停止并删除容器时,它们 创建一个新的。我尝试过

docker rmi $(docker images -a -q)
Untagged: tomcat:latest
Untagged: tomcat@sha256:cea26a23e1ebdbebdddde1e02a10e655b0b386d8de6002301a037a08be87a12f
Deleted: sha256:5377fd8533c34a4b1a909ff56d1ccc5b61f8bda1901b1c3c7e69cc3534cf25c2
Deleted: sha256:6593cb376a4f95448251a326806ad3f452481a6f96e9b1debf4fcc5bf5413328
Deleted: sha256:065f6b7f3a853eff8da8b651f8574320e7637b811fb10adf588f1c8a36a42793
Deleted: sha256:0388835b21d764f276baf4be8396cc22e84a6f442402d03b437fc61e81e4acea
Deleted: sha256:055d339f8c77be047597bab013bef0056e2b6a414a1225b12539637dcb59482b
Deleted: sha256:58136eb1ff2719ed3f6a8ef410a2989960f99a7988112e81017638b4527be1c4
Deleted: sha256:e6d9e14c5186b2546854328eb17f83bb72690820379af71d8b4ad7a566e77085
Deleted: sha256:81bea2e4eb39ed9ed1ceb0e8ca05cefbdc96bd0b38266c26990c1eb0ed528612
Deleted: sha256:5707f840eb6421a463261e9f62c9fcc691facd718993a666d5c86751ebb57cc3
Deleted: sha256:706c0c43e07bd77aba42160b0d0158297caec76c4da6566d856f28b1754f2265
Deleted: sha256:0db06dff9d9aeb9bed4edde7bd772ad0f3aea497c129d48ed587664d098c6c41
Untagged: nginx:latest
Untagged: nginx@sha256:12db363acf5b2d2f9f5fed240e228a04692bdac68402430fbd2f720c3a967d01
Deleted: sha256:62c261073ecffe22a28f2ba67760a9320bc4bfe8136a83ba9b579983346564be

但是

Error response from daemon: conflict: unable to delete ba2730fb15d4 (cannot be forced) - image is being used by running container cc3dd153eea1
Error: No such image: 81f545dad9c7
Error: No such image: 19b3e7672486
Error: No such image: 28ce82ebe756
Error: No such image: b860ab44e93e
Error response from daemon: conflict: unable to delete 8dbf7c60cf88 (cannot be forced) - image is being used by running container e9978660072a
Error response from daemon: conflict: unable to delete e10df791f13c (cannot be forced) - image is being used by running container 3b42e7e6e4f2

我克隆了代码votingapp 问题在于映像是通过docker swarm部署的

docker stack deploy --compose-file docker-stack.yml vote

我没有太多的蜂群经验,我不确定是否应该离开蜂群。

docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
iiq90umkuazv565mzw0imyycg *   miki                Ready               Active              Leader              18.09.6

如何摆脱困境?

2 个答案:

答案 0 :(得分:0)

docker service ls

docker service rm <service_ID>

答案 1 :(得分:-1)

我将首先检查一些这种方法: Docker error cannot delete docker container, conflict: unable to remove repository reference

这是有关如何删除容器的文档。 https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes

如果您要删除所有容器,则可以使用:

docker system prune

要另外删除所有停止的容器和所有未使用的图像(不仅仅是悬空的图像),请在命令中添加-a标志:

docker system prune -a