批量解决docker映像无法删除问题

 

 

 

 

删除映像时,出现以下错误

Error response from daemon: conflict: unable to delete 9f8c08f4755e (must be forced) - image is referenced in multiple repositories

查看映像,确实出现大量ID相同,repository或tag不同的映像

ps images
# docker images
REPOSITORY                                     TAG                 IMAGE ID            CREATED             SIZE
xproject/api/product-api-service               1.3.0-RELEASE       9f8c08f4755e        2 hours ago         219 MB
xproject/api/product-api-service               latest              9f8c08f4755e        2 hours ago         219 MB
xproject/composite/product-composite-service   1.3.0-RELEASE       c47d0e8e3983        2 hours ago         216 MB
xproject/composite/product-composite-service   latest              c47d0e8e3983        2 hours ago         216 MB
xproject/core/review-service                   1.3.0-RELEASE       69f8dad275b8        2 hours ago         215 MB
xproject/core/review-service                   latest              69f8dad275b8        2 hours ago         215 MB
xproject/core/product-service                  1.3.0-RELEASE       1fcbdf73e91f        2 hours ago         215 MB
xproject/core/product-service                  latest              1fcbdf73e91f        2 hours ago         215 MB
xproject/support/zipkin-server                 1.3.0-RELEASE       3e34577e0e98        2 hours ago         223 MB
xproject/support/zipkin-server                 latest              3e34577e0e98        2 hours ago         223 MB
xproject/support/auth-server                   1.3.0-RELEASE       008ffb4ce925        2 hours ago         232 MB
xproject/support/auth-server                   latest              008ffb4ce925        2 hours ago         232 MB
xproject/support/turbine-server                1.3.0-RELEASE       e5c4e8165ec9        2 hours ago         216 MB
xproject/support/turbine-server                latest              e5c4e8165ec9        2 hours ago         216 MB
xproject/support/hystrix-dashboard             1.3.0-RELEASE       69f77c7c7af0        2 hours ago         217 MB
xproject/support/hystrix-dashboard             latest              69f77c7c7af0        2 hours ago         217 MB
xproject/support/zuul-server                   1.3.0-RELEASE       e03b8a22505c        2 hours ago         219 MB
xproject/support/zuul-server                   latest              e03b8a22505c        2 hours ago         219 MB
xproject/support/eureka-server                 1.3.0-RELEASE       770629d65b5e        2 hours ago         219 MB
xproject/support/eureka-server                 latest              770629d65b5e        2 hours ago         219 MB
xproject/support/config-server                 1.3.0-RELEASE       5a68713ce2ed        2 hours ago         204 MB
xproject/support/config-server                 latest              5a68713ce2ed        2 hours ago         204 MB
docker.io/anapsix/alpine-java                  8_jdk               1fd6bac7d0ce        5 months ago        172 MB

 参考CSDN文章:https://blog.csdn.net/JackLiu16/article/details/80581709

可以用名称删除,但这样太慢。

参考另外一篇文章https://www.cnblogs.com/q4486233/p/6482711.html中批量删除untagged images,也就是那些id为<None>的image的映像的作法,

docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

将<none>替换为上面images中的模式字符 :

docker rmi $(docker images | grep "^xproject" | awk "{print $3}")

顺序删除全部映像。

 

将该文备忘如下:
 

1.停止所有的container,这样才能够删除其中的images:

docker stop $(docker ps -a -q)

如果想要删除所有container的话再加一个指令:

docker rm $(docker ps -a -q)

2.查看当前有些什么images

docker images

3.删除images,通过image的id来指定删除谁

docker rmi <image id>

想要删除untagged images,也就是那些id为<None>的image的话可以用

docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

要删除全部image的话

docker rmi $(docker images -q)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值