docker删除镜像遇到 conflict: unable to remove / conflict: unable to delete

查看镜像:

删除失败:

$ docker rmi centos:latest                                                                                                                              
Error response from daemon: conflict: unable to remove repository reference "centos:latest" (must force) - container 9270e5028f22 is using its referenced image 1e1148e4cc2c

$ docker rmi 1e1148e4cc2c
Error response from daemon: conflict: unable to delete 1e1148e4cc2c (cannot be forced) - image has dependent child images

docker ps查看发现没有在运行的。

于是查看依赖关系:

$ docker image inspect --format='{{.RepoTags}} {{.Id}} {{.Parent}}' $(docker image ls -q )
[antony314/centos:v1] sha256:47dd3157ad261529904d1e44ceb974c674a9542e6510ea0e1c784346d2c57713 sha256:1e1148e4cc2c148c6890a18e3b2d2dde41a6745ceb4e5fe94a923d811bf82ddb
[antony/ubuntu:latest] sha256:91e3b07b358dc003248553e7d40275897acbfce7bdf0524ece6ba797e3816251 sha256:9b9cb95443b5f846cd3c8cfa3f64e63b6ba68de2618a08875a119c81a8f96698
[hello-world:latest] sha256:fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e 
[ubuntu:14.04] sha256:7e4b16ae8b23e239ab03a413febb51e204e294cb2bf0e45cc4aa7bed7d7f704e 
[centos:latest] sha256:1e1148e4cc2c148c6890a18e3b2d2dde41a6745ceb4e5fe94a923d811bf82ddb 
[ubuntu:15.10] sha256:9b9cb95443b5f846cd3c8cfa3f64e63b6ba68de2618a08875a119c81a8f96698 

确实自己新commit的antony314/centos是依赖了官方镜像centos,

于是先删除antony314/centos:

注意不是latest需要带上tag名称,这里是v1

看起来是成功了,继续删除原image:

$  docker rmi centos:latest 
Error response from daemon: conflict: unable to remove repository reference "centos:latest" (must force) - container 9270e5028f22 is using its referenced image 1e1148e4cc2c

$ docker rmi 1e1148e4cc2c
Error response from daemon: conflict: unable to delete 1e1148e4cc2c (must be forced) - image is being used by stopped container 9270e5028f22

注意这里用image id删除的时候报错的内容不一样了,看来还是container没有关闭。

但是一样,用docker ps 看还是没有在运行的容器:

但是查看所有的话,docker ps -a:

这大概就是实例化的和运行中的区别。

于是仍然先删除container,最后终于删除镜像成功:

$ docker rm 67a06fa62c7d
$ docker rm 9270e5028f22
$ docker rmi 1e1148e4cc2c
Untagged: centos:latest
Untagged: centos@sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Deleted: sha256:1e1148e4cc2c148c6890a18e3b2d2dde41a6745ceb4e5fe94a923d811bf82ddb
Deleted: sha256:071d8bd765171080d01682844524be57ac9883e53079b6ac66707e192ea25956

 

最后,附几个常用停止和删除容器的命令:

docker stop containerId   // containerId 是容器的ID

docker rm containerId   // containerId 是容器的ID

docker stop $(docker ps -a -q)   // stop停止所有容器 

docker rm $(docker ps -a -q)   // remove删除所有容器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值