如何判断哪个Docker映像可以安全删除?

当我运行docker image ls我看到这个

 REPOSITORY TAG IMAGE ID CREATED SIZE app-bunlong latest 46faf4e647e1 9 minutes ago 2.59GB <none> <none> c012c1e2eb45 4 hours ago 2.59GB <none> <none> a2013debf751 5 hours ago 2.59GB web-bunlong latest 9da65074196b 5 hours ago 182MB <none> <none> 0bbb2f67083c 5 hours ago 2.59GB <none> <none> af18b070061b 29 hours ago 182MB <none> <none> 186a8fac122e 35 hours ago 1.67GB <none> <none> 0f90c1bb12a3 35 hours ago 182MB bheng/bunlongheng-external latest 70374ef1cb11 12 days ago 114MB bunlongheng-external latest 70374ef1cb11 12 days ago 114MB bheng/bunlongheng-external <none> 4d8cb528a4f3 13 days ago 207MB <none> <none> b94009e70416 13 days ago 631MB bheng/2018-web latest 1fa699f171de 2 weeks ago 16.9MB bheng/bunlongheng-internal latest 1fa699f171de 2 weeks ago 16.9MB 2018-web latest 1fa699f171de 2 weeks ago 16.9MB bunlongheng-internal latest 1fa699f171de 2 weeks ago 16.9MB <none> <none> 880d8e6713cf 2 weeks ago 631MB bheng/2018-external latest 128d208a6c83 2 weeks ago 207MB 2018-external latest 128d208a6c83 2 weeks ago 207MB bheng/2018-web <none> 128d208a6c83 2 weeks ago 207MB nginx latest 9e7424e5dbae 2 weeks ago 108MB node 8-alpine 4db2697ce114 4 weeks ago 67.7MB bheng_web latest d5a0ea011c0a 5 weeks ago 182MB <none> <none> 957c22ababec 5 weeks ago 182MB docker_web latest 70b443ed0495 5 weeks ago 182MB docker_app latest 509d58a68224 5 weeks ago 756MB bheng_app latest 509d58a68224 5 weeks ago 756MB mysql 5.6 96dc914914f5 5 weeks ago 299MB mysql latest 5fac85ee2c68 8 weeks ago 408MB redis latest 1fb7b6c8c0d0 2 months ago 107MB alpine 3.6 76da55c8019d 2 months ago 3.97MB nginx 1.13.3-alpine ba60b24dbad5 5 months ago 15.5MB keymetrics/pm2-docker-alpine 6 4a09bfc067d6 5 months ago 75.3MB dockercloud/cli latest 051238cd0a37 6 months ago 64.2MB andrewmclagan/nginx-hhvm latest ec6cc741eb0e 7 months ago 580MB nginx 1.10 0346349a1a64 8 months ago 182MB php 7.0.8-fpm 75b880f3a420 17 months ago 375MB tutum/haproxy latest 33bc771bec1e 18 months ago 232MB php 7.0.4-fpm 81d7a2fdc6dc 21 months ago 494MB 

我如何知道是否安全删除哪个图像?

我的注意力是把所有这些都删除,但是我不确定在做这些之前我应该​​多做些什么。

您可以使用docker image prune删除“悬挂”图像; 那些没有被标记的(例如<none>并且没有被任何正在运行的容器引用。

我发现docker image prune -a更有用的。 它将删除正在运行的容器未使用的任何图像。 在这个意义上,修剪-a是一个清理步骤,您可以在环境正确运行后执行。

被称为摇晃的图像可以安全地移除。 那些没有标签的图像。 当出现图像的新构build并且新图像使标签离开具有<none>:<none>标签的悬挂图像时,它们产生。

悬挂的图像可以使用docker images --filter "dangling=true"镜像列出 – docker images --filter "dangling=true" ,可以通过运行docker image prune删除。