我最近开始使用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的东西不存在,但我正在寻找具有类似想法的东西。
当前回答
检查码头集装箱体积
码头系统df
修剪所有图像和卷
docker prune--全部
其他回答
删除所有图像,但至少有一个容器与其关联
$ 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}}'
xargs的另一种方式(仅限Unix)
docker image ls -q | xargs -I {} docker image rm -f {}
要删除所有Docker本地Docker镜像,请执行以下两个步骤:
步骤1:docker图像(列出所有具有id的docker图像)
example :
REPOSITORY TAG IMAGE ID CREATED SIZE
pradip564/my latest 31e522c6cfe4 3 months ago 915MB
步骤2:docker image rm 31e522c6cfe4(图像ID)
OUTPUT : image deleted
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-说明