5

Docker删除images问题

 3 years ago
source link: https://www.meirenji.info/2019/03/13/Docker%E5%88%A0%E9%99%A4images%E9%97%AE%E9%A2%98/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Docker删除images问题

发表于 2019-03-13

| 分类于 DevOps

| 0 Comments

偶然间发现服务器上有很多镜像占用不少空间,想清理一下。结果直接进行删除报错

主流的方法有两种

docker rmi -f

方法二:批量删除容器,再删除镜像

# 停止所有容器
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker stop

# 删除所有容器
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker rm

# 删除所有none镜像
docker images|grep none|awk '{print $3 }'|xargs docker rmi

查找出所有在指定 image 之后创建的 image 的父 image,本示例看得出是同一个依赖镜

docker image inspect --format='{{.RepoTags}} {{.Id}} {{.Parent}}' $(docker image ls -q --filter since=xxxxxx)

删除关联的依赖镜像,关联的none镜像也会被删除

参考文档:

image has dependent child images


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK