我想在Docker中删除容器,但是当你想删除时发生了一个错误

在移除容器之前,我的下一步是查看现有容器的列表

sts@Yudi:~/docker$ sudo docker ps -as

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                    PORTS               NAMES                  SIZE
78479ffeba5c        ubuntu              "/bin/bash"         42 hours ago        Exited (0) 42 hours ago                       sharp_wescoff          81 B (virtual 187.7 MB)
0bd2b54678c7        training/webapp     "python app.py"     5 days ago          Exited (0) 5 days ago                         backstabbing_ritchie   0 B (virtual 323.7 MB)
0adbc74a3803        training/webapp     "python app.py"     5 days ago          Exited (143) 5 days ago                       drunk_feynman          0 B (virtual 323.7 MB)

一个我想删除列表,即“training / webapp” 但是出现了一个错误

sts@Yudi:~/docker$ sudo docker rmi training/webapp
Error response from daemon: conflict: unable to remove repository reference "training/webapp" (must force) - container 0bd2b54678c7 is using its referenced image 54bb4e8718e8
Error: failed to remove images: [training/webapp]

容器是否在映像中运行?

请帮助


当前回答

在docker中删除“网络未找到”

检查我们无法删除的网络

docker network inspect [<id> or <name>]

断开网络

docker network disconnect -f [<networkID> or <networkName>] [<endpointName> or <endpointId>]

删除未使用的网络

docker network prune

其他回答

Noticed this is a 2-years old question, but still want to share my workaround for this particular question: Firstly, run docker container ls -a to list all the containers you have and pinpoint the want you want to delete. Secondly, delete the one with command docker container rm <CONTAINER ID> (If the container is currently running, you should stop it first, run docker container stop <CONTAINER ID> to gracefully stop the specified container, if it does not stop it for whatever the reason is, alternatively you can run docker container kill <CONTAINER ID> to force shutdown of the specified container). Thirdly, remove the container by running docker container rm <CONTAINER ID>. Lastly you can run docker image ls -a to view all the images and delete the one you want to by running docker image rm <hash>.

这两个命令简单地解决了我的问题。

停止特定的容器。

docker stop <container_id>

强制删除映像,即使它在多个存储库中被引用。

docker rmi -f <container_id>

可以使用-f选项强制删除容器。

Sudo docker rmi -f training/webapp

你可以在删除之前使用sudo docker stop training/webapp停止容器

在docker中删除“网络未找到”

检查我们无法删除的网络

docker network inspect [<id> or <name>]

断开网络

docker network disconnect -f [<networkID> or <networkName>] [<endpointName> or <endpointId>]

删除未使用的网络

docker network prune

如果你想清理docker映像和容器

注意:这会冲掉所有东西

停止所有容器

docker stop $(docker ps -a -q)

移除所有容器

docker rm $(docker ps -a -q)

删除所有图片

docker rmi -f $(docker images -a -q)