delete docker image failed

problem

docker images -a

1
2
3
4
5
6
7
8
9
10
11
[root@CN-BJI-D-de9f66 ~]# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 72dc10d3deba 22 hours ago 230MB
tdtest latest e3ad759bb993 22 hours ago 230MB
<none> <none> 820bc1802af7 22 hours ago 230MB
...
<none> <none> ac8cea40eaa0 22 hours ago 223MB
centos latest 0f3e07c0138f 2 weeks ago 220MB
redis latest 01a52b3b5cd1 2 weeks ago 98.2MB
ubuntu latest 2ca708c1c9cc 3 weeks ago 64.2MB
redis alpine ed7d2ff5a623 8 weeks ago 29.3MB

when put command docker rmi 820bc1802af7, <none>:<none> image delete fail.

1
Error response from daemon: conflict: unable to delete 820bc1802af7 (cannot be forced) - image has dependent child images

this is cause by has other images depend on this image 820bc1802af7.
use docker image inspect, find current image’s child image, repository tag name.

1
2
[root@CN-BJI-D-de9f66 ~]# docker image inspect --format='{{.RepoTags}} {{.Id}} {{.Parent}}' $(docker image ls -q --filter since=820bc1802af7)
[tdtest:latest] sha256:e3ad759bb99351a4951df11113e0ad3914a26d55e99e5243e13ebac19373efae sha256:8abd1595d4dfc922b81825940c0f6d73034eeb10b3e2b12a78b3d0e33d78588e

mechanism

kind one

<none>:<none> images which be related to the image be deleted will be deleted as will.
this kind of <none>:<none> is middle image, it won’t occupy space.

kind two

make a docker image docker build -t hello-world ./

1
2
FROM centos:latest
RUN echo 'hello world'

when centos have a new release, build hello-world image again, it will depend on the latest centos.
the hello-world depend on older centos, will become <none>:<none> dangling image.
this kind of <none>:<none> occupy space, it was originally tag image.

all docker file store at /var/lib/docker/graph in default, docker be called graph layer database.
use command docker rmi $(docker images -f "dangling=true" -q) to delete wandering image layer.

other command

1
2
3
4
5
6
7
8
# stop all container
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker stop

# delete all container
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker rm

# delete all none container
docker images|grep none|awk '{print $3 }'|xargs docker rmi

http://www.ibloger.net/article/3217.html
https://segmentfault.com/a/1190000011153919
https://blog.csdn.net/sin_geek/article/details/86736417