阅读 8

Docker 删除空白TAG和REPOSITORY的镜像

初步学习了docker,发现一个问题。在误操作后。会遗留一个只有IMAGE ID 的空白镜像

如何删除它,尝试了几次才成功。

当你想删除空白TAG和空白REPOSITORY的镜像时,列出当前镜像

[root@iZ25kr7psegZ ~]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
azkaban_centos          latest              8993c0c20f01        24 hours ago        244MB
<none>                  <none>              d2dcb7c1f1ce        2 days ago          1.08GB
mysql                   latest              990386cbd5c0        7 days ago          443MB
centos                  latest              9f38484d220f        2 months ago        202MB
hello-world             latest              fce289e99eb9        4 months ago        1.84kB复制代码

执行删除语句 docker rmi IMAGE ID 

[root@iZ25kr7psegZ ~]# docker rmi d2dcb7c1f1ce
Error response from daemon: conflict: unable to delete d2dcb7c1f1ce (must be forced) - image is being used by stopped container cde37d151fdf复制代码

这边提示你需要停止镜像所依赖的容器

[root@iZ25kr7psegZ ~]# docker stop cde37d151fdf
cde37d151fdf复制代码

然后删除这个容器。

[root@iZ25kr7psegZ ~]# docker rm cde37d151fdf
cde37d151fdf复制代码

接着就可以删除这个空白的镜像了。

[root@iZ25kr7psegZ ~]# docker rmi d2dcb7c1f1ce
Deleted: sha256:d2dcb7c1f1ce916ea67a0a6c63cda40c62fa8dbc985845e64f3fafe9a37664f1
Deleted: sha256:86ad6d366bb4d0c9e4b176bc220ff8d421902e2bcb197c7c017f8da854c3c72d
Deleted: sha256:128e444c34b373f5e553883c65f676efdb2be22684bcbcf141fb724a7b3de316
Deleted: sha256:15d26edbae6fafd6acad6e3308445846202230b66c6199cb236268f932b59ce8复制代码

再次查询一下镜像列表

[root@iZ25kr7psegZ ~]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
azkaban_centos          latest              8993c0c20f01        24 hours ago        244MB
<none>                  <none>              adbcb407e207        2 days ago          571MB
mysql                   latest              990386cbd5c0        7 days ago          443MB
centos                  latest              9f38484d220f        2 months ago        202MB
hello-world             latest              fce289e99eb9        4 months ago        1.84kB复制代码

发现所占的SIZE从1.08G降到了571M。说明还存在另一个容器在保存这层镜像。可以想象成俄罗斯套娃。需要一层层的删除。肯定是做了过多的docker commit 操作。重复操作过程中发现有时候一个镜像对应着不同的容器。每提示一个容器ID就执行一次stop和rm操作。应该是启动次数过于频繁造成的镜像被重复加载。最终结果当然是删除干净了。

[root@iZ25kr7psegZ ~]# docker rmi cb9f332b969f
Deleted: sha256:cb9f332b969ff425ef7bf781a1d7dff720dfa32a6e77a20347552b76f6b763eb
Deleted: sha256:2a9ae33d11aadc05d24b58f67c6eb577c64eceff0528d06207e49963257e5f24
[root@iZ25kr7psegZ ~]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
azkaban_centos          latest              8993c0c20f01        24 hours ago        244MB
mysql                   latest              990386cbd5c0        7 days ago          443MB
centos                  latest              9f38484d220f        2 months ago        202MB
hello-world             latest              fce289e99eb9        4 months ago        1.84kB复制代码


关注下面的标签,发现更多相似文章
评论