执行docker build的时候,经常会产生一些中间镜像,执行docker iamges -a可以看到。

coffee@myserver:/home/coffee$ sudo docker images -a
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>              <none>              8684a0a8943f        20 minutes ago      188 MB
<none>              <none>              286290c56fd0        20 minutes ago      188 MB
<none>              <none>              3772db9ecb08        22 minutes ago      188 MB
<none>              <none>              c36c7f0c261c        22 minutes ago      188 MB
<none>              <none>              35fe1e378fed        22 minutes ago      188 MB
<none>              <none>              f4adb7962cc3        22 minutes ago      188 MB
<none>              <none>              6f78ecfe7ad3        22 minutes ago      188 MB
<none>              <none>              e1c377762a66        22 minutes ago      188 MB
<none>              <none>              c90d308e2c8c        18 hours ago        222.9 MB
<none>              <none>              1c7659921e20        18 hours ago        222.9 MB
<none>              <none>              52ac6c746173        18 hours ago        188 MB
<none>              <none>              df672b3d59a2        18 hours ago        188 MB
<none>              <none>              d58b5b8976d1        18 hours ago        188 MB
<none>              <none>              963b43ce0054        18 hours ago        188 MB
<none>              <none>              7c86cb6fc08a        18 hours ago        188 MB
<none>              <none>              240000b69791        18 hours ago        188 MB
<none>              <none>              c9a620c963ea        18 hours ago        188 MB
<none>              <none>              63f44c0b4189        4 days ago          188 MB
ubuntu              14.04               a437f423d026        4 days ago          188 MB
<none>              <none>              f44e17f97457        4 days ago          188 MB
<none>              <none>              3f25bbbde971        4 days ago          188 MB
<none>              <none>              a578980e967c        4 days ago          188 MB
<none>              <none>              3aa22c9020a0        4 days ago          187.8 MB

如果直接用命令

sudo docker rmi $(sudo docker images --filter dangling=true -q)

容易出现报错:

coffee@myserver:/home/coffee$ sudo docker rmi $(sudo docker images --filter dangling=true -q)
Error response from daemon: conflict: unable to delete 8684a0a8943f (must be forced) - image is being used by stopped container ecbd5ade37e8
Error response from daemon: conflict: unable to delete c90d308e2c8c (must be forced) - image is being used by stopped container 871bd66088c4
Error: failed to remove images: [8684a0a8943f c90d308e2c8c]

此时需要先停止并删除容器,依次执行以下命令

sudo docker ps -a | grep "Exited" | awk '{print $1 }'|xargs sudo docker stop
sudo docker ps -a | grep "Exited" | awk '{print $1 }'|xargs sudo docker rm
sudo docker images|grep none|awk '{print $3 }'|xargs sudo docker rmi

就可以删除docker build产生的临时镜像。

参考:
docker强制批量删除none的image镜像
docker images -a,怎么查出那么多镜像,怎么删除


作者:feiniao8651
来源:CSDN
原文:https://blog.csdn.net/feiniao8651/article/details/60329456
版权声明:本文为博主原创文章,转载请附上博文链接!

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐