docker 删除镜像

本文演示了如何使用Docker命令查看系统中镜像和容器的使用情况,包括`docker system df`来检查资源占用,以及如何删除镜像。在删除镜像时遇到了因容器正在使用而产生的冲突,通过添加`-f`参数强制删除解决了问题。此外,还展示了批量删除镜像的方法。
摘要由CSDN通过智能技术生成

docker system df

查看docker使用情况

[root@localhost ~]# docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          3         1         182MB     182MB (99%)
Containers      1         0         0B        0B
Local Volumes   0         0         0B        0B
Build Cache     0         0         0B        0B
[root@localhost ~]#

 docker rmi hello-world

通过镜像名称从docker仓库中删除镜像

[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
ubuntu        latest    27941809078c   4 weeks ago     77.8MB
hello-world   latest    feb5d9fea6a5   9 months ago    13.3kB
redis         6.0.8     16ecd2772934   20 months ago   104MB
[root@localhost ~]# docker rmi hello-world
Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container 11a256a8709f is using its referenced image feb5d9fea6a5

[root@localhost ~]# docker rmi -f feb5d9fea6a5
Untagged: hello-world:latest
Untagged: hello-world@sha256:13e367d31ae85359f42d637adf6da428f76d75dc9afeb3c21faea0d976f5c651
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
[root@localhost ~]#

报错了,但是可以通过-f 参数强制删除

docker rmi feb5d9fea6a5

通过镜像ID从docker仓库中删除镜像

[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
ubuntu        latest    27941809078c   4 weeks ago     77.8MB
hello-world   latest    feb5d9fea6a5   9 months ago    13.3kB
redis         6.0.8     16ecd2772934   20 months ago   104MB
[root@localhost ~]# docker rmi feb5d9fea6a5
Error response from daemon: conflict: unable to delete feb5d9fea6a5 (must be forced) - image is being used by stopped container 11a256a8709f
[root@localhost ~]#
[root@localhost ~]# docker rmi -f feb5d9fea6a5
Untagged: hello-world:latest
Untagged: hello-world@sha256:13e367d31ae85359f42d637adf6da428f76d75dc9afeb3c21faea0d976f5c651
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
[root@localhost ~]#

 docker rmi aaa  bbb ccc

同时删除多个镜像 

删除所有的docker镜像 

docker rmi  -f $(docker images -qa) 或者

docker rmi  -f `docker images -qa`

其实就是两个命令的组合使用,先通过docker images -qa查出来所有的镜像ID,然后再删除

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

haowll

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值