美文网首页
docker删除镜像那些事

docker删除镜像那些事

作者: 木脑 | 来源:发表于2019-07-26 14:54 被阅读0次

    REPOSITORY和TAG都是<none>,IMAGE ID有效

    这种称为dangling状态,删除的方式有两种:

    docker rmi $(docker images -q -f dangling=true)
    
    docker image prune
    

    REPOSITORY不为<none>,TAG是<none>,IMAGE ID有效

    如果无重复的IMAGE ID,可以通过下列方式删除:

    docker images|grep none|awk '{print $3}'|xargs sudo docker rmi -f
    

    REPOSITORY不为<none>,TAG是<none>,IMAGE ID无效

    如: image.png

    就无法通过上列所有的命令删除,执行命令会发生错误提示:

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

    如果要清理,需要用到digest
    方法:在docker images查看镜像列表时,默认是不会显示镜像的digest的。需要手动加上--digests=true参数,才能看到形如“sha256:xxxxx”的digest信息。这个时候,用镜像的REPOSITORY➕@➕digest即可精确引用到该镜像,从而删除。

    [root@localhost]# docker images --digests=true | grep 27600aa3d7f1
    springmvc-demo                                      <none>              sha256:b3e89c95260685b18b31acb078b168c30a3b94ba561801bf374ccec0e7c622c6   27600aa3d7f1        2 months ago        463 MB
    
    [root@localhost]# docker rmi springmvc-demo @sha256:b3e89c95260685b18b31acb078b168c30a3b94ba561801bf374ccec0e7c622c6
    Untagged: registry.syswinsoft.com/bussiness/springmvc-demo@sha256:b3e89c95260685b18b31acb078b168c30a3b94ba561801bf374ccec0e7c622c6
    

    大功告成,不用考虑清空镜像库。
    PS:若是因为运行,或者还有容器存在不能删除,就通过docker ps -a和docker rm批量删除即可。本文主要是利用digest进行删除none镜像。

    相关文章

      网友评论

          本文标题:docker删除镜像那些事

          本文链接:https://www.haomeiwen.com/subject/kiorrctx.html