docker rmi删除镜像错误

avatar 2020年5月14日21:54:33 评论 1,857 次浏览

创建容器的时候拉取了几个镜像,测试后步需要了,就准备删除,先看一下我要删除的镜像:

[root@www.wulaoer.org wulaoer]# docker images
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
pinpoint-agent                     latest              19af8d2f2cfc        3 days ago          1.12GB
xx.xx.xx.xx/devops/pinpoint-test   latest              19af8d2f2cfc        3 days ago          1.12GB

两个镜像的id是一样的,在我删除的就是就报错了,

[root@www.wulaoer.org wulaoer]# docker rmi 19af8d2f2cfc
Error response from daemon: conflict: unable to delete 19af8d2f2cfc (must be forced) - image is referenced in multiple repositories

这种错误是因为docker rmi的是删除所有指向该镜像的标签,然后删除镜像本身,不过如果镜像中存在多个标签使用docker rmi是无法删除镜像的,这种错误就是说明镜像中存在多个标签,所以无法删除。若要删除可以使用docker rmi -f强制删除,不过不推荐,可以使用docker ps -a查看一下是否有依赖镜像的容器,删除容器后在删除镜像,如果没有容器在强制删除。

[root@www.wulaoer.org wulaoer]# docker rmi -f 19af8d2f2cfc
Untagged: xx.xx.xx.xx/devops/pinpoint-test:latest
Untagged: xx.xx.xx.xx/devops/pinpoint-test@sha256:ae094caa2adedb3187a643e8743954d650d1d7a9a93480e08a37450e6f278ea6
Untagged: pinpoint-agent:latest
Deleted: sha256:19af8d2f2cfc68ab287fe46285237e719ede7ea0fa0d852bef2a6cae9b770742
Deleted: sha256:92759204755a59272c138a9513d84bcd99dc2d36232a22bf295c68e53266a363
Deleted: sha256:91c0baf6e85fcd8b4c62f0d938ab6f167e72de748c84ebe0192d726b3ed7876e
Deleted: sha256:dfa76309ae89fe3f4cf2d85eec482b983317d9a1f5a25e307663dc9f5f176e4c
Deleted: sha256:bfdedc04280daa8b4d0ad8198c346452fccb9ee307a0e727084a599c20574cb0
Deleted: sha256:77b174a6a187b610e4699546bd973a8d1e77663796e3724318a2a4b24cb07ea0
[root@www.wulaoer.org wulaoer]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

这样就删除了多标签的镜像,不过前提是依赖镜像的容器不工作了,或者不需要了,才去墙纸删除,否则不建议。

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: