如何删除无效的<none>Docker镜像?

发布时间:2020-07-16 21:41:52 作者:yunweilu
来源:网络 阅读:737

如何删除无效的<none>Docker镜像?

开始之前

为什么会有 none 这样命名的镜像?
这些镜像 docker 称为 虚悬镜像,当镜像被新的镜像覆盖时候,老版本镜像名称会变成 none

例如当前docker宿主机已经存在 nginx:latest 镜像,而不久后 docker hub 推送了新版的 nginx 镜像。

当你再次 docker pull nginx:latest 下载镜像时,老版本镜像被覆盖名称也将变成 none

另外一个需要注意问题的是 从 docker 1.13.1 版本开始引入 docker image 命令,新命令集成了 list、rm、build、tag、push、pull, 等功能,用于替代 images 、build 、rmi 、tag 等二级命令。

考虑到兼容性新版本的 docker 仍然可以使用这些旧的二级子命令,例如 docker pull nginxdocker image pull nginx 它们功能都是相同的。

我们需要做的就是找到并删除这些名称带有 none 无效镜像。

操作步骤
  1. 列出带有 none 字符的镜像
docker images -f dangling=true | head -n 3
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              d31c5d38836d        3 days ago          1.03GB
<none>              <none>              10d22b8d83b3        6 days ago          1.03GB

# 这两个命令功能相同
docker image ls -f dangling=true | head -n 3
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              d31c5d38836d        3 days ago          1.03GB
<none>              <none>              10d22b8d83b3        6 days ago          1.03GB
  1. 删除无效镜像
docker image prune

WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Deleted Images:
deleted: sha256:d..省略..3e5c4918ee576d729a4b
# ...省略
  1. 也可以使用 rmi 命令删除
docker rmi `docker image ls -f dangling=true -q`
命令帮助
docker image

如何删除无效的<none>Docker镜像?

docker rmi -h
Flag shorthand -h has been deprecated, please use --help

Usage:  docker rmi [OPTIONS] IMAGE [IMAGE...]

Remove one or more images

Options:
  -f, --force      Force removal of the image
      --no-prune   Do not delete untagged parents
小结

最后来总结下文章中的知识点

参考文章

doker&k8s Qun [703906133]

推荐阅读:
  1. docker中怎么删除容器和镜像
  2. Docker 本地导入镜像/保存镜像/载入镜像/删除镜像的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

docker image none

上一篇:PowerShell 学习笔记——文件系统

下一篇:Android使用代码设置Dialog的Style

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》