Docker 镜像清理(docker image prune)

Remove all dangling images. If -a is specified, will also remove all images not referenced by any container.

删除所有 maintainerXYBMrBird 的镜像。

docker image prune --filter="label=maintainer=XYB" --filter="label=maintainer=MrBird"
  

参数

  • --all-a

    清除所有没有容器引用的镜像。

  • --filter

    筛选要删除的镜像。

    • until (<timestamp>) - only remove images created before given timestamp
    • label (label=<key>, label=<key>=<value>, label!=<key>, or label!=<key>=<value>) - only remove images with (or without, in case label!=... is used) the specified labels.
  • -f--force

    跳过提示信息强制执行清理操作。

清理 Jenkins 打包服务器上的镜像

由于 --filter 指定的 maintainer 无法起作用,所以修改为使用 grep 来删除旧的镜像。
示例如下:

docker images|grep t_|awk '{print $3}'|xargs docker rmi
  

参考

  1. Docker对象清理
  2. docker image prune