我最近开始使用Docker,从未意识到我应该使用Docker compose down而不是ctrl-c或Docker composestop来摆脱我的实验。我现在在本地有大量不需要的docker图像。
我是否可以运行一个标志来删除所有本地docker图像和容器?
类似docker rmi-all-force-all-flag的东西不存在,但我正在寻找具有类似想法的东西。
我最近开始使用Docker,从未意识到我应该使用Docker compose down而不是ctrl-c或Docker composestop来摆脱我的实验。我现在在本地有大量不需要的docker图像。
我是否可以运行一个标志来删除所有本地docker图像和容器?
类似docker rmi-all-force-all-flag的东西不存在,但我正在寻找具有类似想法的东西。
当前回答
删除所有停止的容器和所有未使用的图像。
docker系统prune-a
其他回答
docker image prune -a
删除所有未使用的图像,而不仅仅是悬挂的图像。将-f选项添加到武力
本地docker版本:17.09.0-ce,Gitcommit:afdb6d4,OS/Arch:darwin/amd64
$ docker image prune -h
Flag shorthand -h has been deprecated, please use --help
Usage: docker image prune [OPTIONS]
Remove unused images
Options:
-a, --all Remove all unused images, not just dangling ones
--filter filter Provide filter values (e.g. 'until=<timestamp>')
-f, --force Do not prompt for confirmation
--help Print usage
使用此选项可删除所有内容:
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-说明
检查码头集装箱体积
码头系统df
修剪所有图像和卷
docker prune--全部
对于Linux Ubuntu用户,下面对我有用。注意事项-它将删除所有内容。
要删除容器及其关联的卷,请使用以下方法:
sudo docker rm -vf $(sudo docker ps -a -q)
要删除图像,请使用以下内容:
sudo docker rmi -f $(sudo docker images -a -q)
删除所有图像,但至少有一个容器与其关联
$ docker images prune -a
要获取图像的所有名称:docker-images-a-q,并在同一行中使用此命令删除所有图像。
docker image rmi $(docker images -a -q)
如果您将图像附加到至少一个正在运行的容器,最好先停止它们。
要删除10天前(240小时)创建的图像,请执行以下操作:
$ docker images prune -a --force --filter "until=240h"
可以使用以下命令进行验证:
$ docker images --format 'table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedAt}}\t{{.Size}}'