您的位置:首页 > 运维架构 > Docker

docker删除中间镜像

2017-03-04 16:02 393 查看
执行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,怎么查出那么多镜像,怎么删除
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  docker images