场景:
在运行docker示例时,在运行删除镜像的命令,如下:
docker rmi hello-world
发生如下报错:
Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container 6bf7c8fb514f is using its referenced image bf756fb1ae65
出现这个问题的原因是删除的这个images可能被依赖与其他的container,
于是乎,查询容器:
docker ps -a
查询结果如下:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b10bead9d787 httpd "httpd-foreground" 5 minutes ago Exited (0) 4 minutes ago sweet_thompson
8ff5c1e24d7c ubuntu:14.04 "/bin/bash" 45 minutes ago Exited (1) 45 minutes ago eloquent_turing
a58b65c662ba training/webapp "python app.py" 2 days ago Exited (137) 2 days ago amazing_volhard
68e267cda2c6 test/ubuntu:v1 "/bin/bash" 2 days ago Exited (0) 2 days ago hungry_mendel
b9293b5d514d test/ubuntu:v1 "/bin/bash" 2 days ago Exited (0) 2 days ago interesting_kowalevski
77ca254ec6f3 ubuntu "/bin/bash" 2 days ago Exited (0) 2 days ago ubuntu-test
70e462d2b4ef ubuntu "/bin/bash" 2 days ago Exited (0) 2 days ago amazing_lumiere
d2c4d889eb8a ubuntu "/bin/bash" 2 days ago Exited (0) 2 days ago serene_black
9dc8fd336c9f ubuntu "/bin/bash" 2 days ago Exited (0) 2 days ago interesting_tereshkova
2e1be34f6db0 ubuntu "/bin/sh -c 'while t…" 2 days ago Exited (137) 2 days ago clever_hamilton
c244e5a63ce1 ubuntu:latest "/bin/bash" 2 days ago Exited (0) 2 days ago pensive_chaplygin
a5e07c4e8cc3 ubuntu "/bin/echo 'Hello wo…" 2 days ago Exited (0) 2 days ago nifty_gauss
4cab1f988c00 ubuntu "bash" 3 days ago Exited (130) 3 days ago dazzling_pike
6bf7c8fb514f hello-world "/hello" 3 days ago Exited (0) 3 days ago unruffled_germain
这下就看到原因了,原来container使用到了这个images,这样问题就简单了
docker rm 6bf7c8fb514f
注意:rm 命令后面的是containerID 根据各自情况变化
然后,再删除images
docker image rm hello-world
运行结果如下:
Untagged: hello-world:latest
Untagged: hello-world@sha256:8e3114318a995a1ee497790535e7b88365222a21771ae7e53687ad76563e8e76
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
Deleted: sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63
成功!!!
附:
删除所有的container
docker rm $(docker ps -a -q)
删除所有的images
docker rmi $(docker images -q)