Docker:如何删除所有本地 Docker 镜像 [英] Docker: How to delete all local Docker images
问题描述
我最近开始使用 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.
推荐答案
For Unix
要删除所有容器,包括其使用的卷,
To delete all containers including its volumes use,
docker rm -vf $(docker ps -aq)
要删除所有图像,
docker rmi -f $(docker images -aq)
请记住,您应该先删除所有容器,然后再删除创建这些容器的所有映像.
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 Windows Powershell,
docker images -a -q | % { docker image rm $_ -f }
对于使用命令行的 Windows,
For Windows using command line,
for /F %i in ('docker images -a -q') do docker rmi -f %i
这篇关于Docker:如何删除所有本地 Docker 镜像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!