红联Linux门户
Linux帮助

docker删除中间镜像

发布时间:2017-03-05 09:51:40来源:linux网站作者:feiniao8651
执行docker build的时候,经常会产生一些中间镜像,执行docker iamges -a可以看到。如下图:
docker删除中间镜像
 
如果直接用命令:
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产生的临时镜像。
 
本文永久更新地址:http://www.linuxdiyf.com/linux/28908.html