zhangguanzhang's Blog

docker无法删除掉镜像的解决方法

字数统计: 307阅读时长: 1 min
2018/02/05

碰到了docker rmi无法删除掉image的问题
版本如下

1
2
[root@guanvps ~]# docker --version
Docker version 17.12.1-ce, build 7390fc6

问题如下,也没有任何容器在运行,重启发现依然无法删除掉

1
2
3
4
5
6
7
8
[root@guanvps ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ae513a47849c 4 weeks ago 109MB
ubuntu latest 452a96d81c30 5 weeks ago 79.6MB
[root@guanvps ~]# docker rmi ae5
Error: No such image: ae5
[root@guanvps ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

重新pull试试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@guanvps ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
Digest: sha256:b1d09e9718890e6ebbbd2bc319ef1611559e30ce1b6f56b2e3b479d9da51dc35
Status: Downloaded newer image for nginx:latest
[root@guanvps ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ae513a47849c 4 weeks ago 109MB
nginx latest ae513a47849c 4 weeks ago 109MB
ubuntu latest 452a96d81c30 5 weeks ago 79.6MB
[root@guanvps ~]# docker rmi ae5
Error response from daemon: conflict: unable to delete ae513a47849c (must be forced) - image is referenced in multiple repositories
[root@guanvps ~]# docker rmi ae5 --force
Error: No such image: ae5
[root@guanvps ~]# docker rmi ae5
Error: No such image: ae5

如上可见依然无法删除,猜测目录文件记录着镜像的信息有残留
进入/var/lib/docker/images/的相关目录

1
2
3
[root@guanvps ~]# cd `find /var/lib/docker -path '*/imagedb/*tent/sha256'`
[root@guanvps sha256]# ls
452a96d81c30a1e426bc250428263ac9ca3f47c9bf086f876d11cb39cf57aeec ae513a47849c895a155ddfb868d6ba247f60240ec8495482eca74c4a2c13a881

发现的确残留文件信息,内容是image的inspect信息,删掉文件后查看没有了

1
2
3
4
[root@guanvps sha256]# rm -f ae5*
[root@guanvps sha256]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 452a96d81c30 5 weeks ago 79.6MB
CATALOG