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

我是否可以运行一个标志来删除所有本地docker图像和容器?

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


当前回答

使用此选项可删除所有内容:

docker system prune -a --volumes

删除所有未使用的容器、卷、网络和映像

WARNING! This will remove:
    - all stopped containers
    - all networks not used by at least one container
    - all volumes not used by at least one container
    - all images without at least one container associated to them
    - all build cache

https://docs.docker.com/engine/reference/commandline/system_prune/#extended-说明

其他回答

docker rmi $(docker images -q) --force
docker images -f dangling=true
docker image prune

xargs的另一种方式(仅限Unix)

docker image ls -q | xargs -I {} docker image rm -f {}

简单方便的命令

删除所有图像

docker rmi $(docker images -a)

删除处于退出状态的容器

docker rm $(docker ps -a -f status=exited -q)

删除处于已创建状态的容器

docker rm $(docker ps -a -f status=created -q)

注意:移除所有容器,然后移除图像

sudo docker images/docker images//带id的图像列表sudo docker rm image<image_id>/docker rm image<image_id>