如何删除所有本地Docker映像 [英] How to delete all local Docker images

查看:156
本文介绍了如何删除所有本地Docker映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用Docker,但从未意识到我应该使用 docker-compose down 而不是 ctrl-c docker-compose stop 摆脱我的实验。我现在在本地有大量不需要的docker映像。

I recently started using Docker and never realized that I should use docker-compose down instead of ctrl-c or docker-compose stop to get rid of my experiments. I now have a large number of unneeded docker images locally.

我可以运行一个标志来删除所有本地docker镜像&容器?

Is there a flag I can run to delete all the local docker images & containers?

类似于 docker rmi --all --force --all标志不存在,但我寻找具有类似想法的东西。

Something like docker rmi --all --force --all flag does not exist but I am looking for something with similar idea.

推荐答案

对于Unix

删除所有容器,包括

docker rm -vf $(docker ps -a -q)

要删除所有图像,

docker rmi -f $(docker images -a -q)

请记住,您应先删除所有容器,然后再删除创建这些容器所用的所有图像。

Remember, you should remove all the containers before removing all the images from which those containers were created.

对于Windows

如果您使用的是Windows(Powershell),

In case you are working on Windows (Powershell),

$images = docker images -a -q
foreach ($image in $images) { docker image rm $image -f }

基于CodeSix的评论,WindowS Powershell的一个衬里,

Based on the comment from CodeSix, one liner for Window's Powershell,

docker images -a -q | % { docker image rm $_ -f }

这篇关于如何删除所有本地Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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