当前位置: 首页 > 知识库问答 >
问题:

Docker错误无法删除Docker容器,冲突:无法删除存储库引用

邵子平
2023-03-14

我想删除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]

容器是否在映像中运行?

请帮忙

共有1个答案

朱祺
2023-03-14

docker映像和docker容器之间是有区别的。检查这个SO问题。

简而言之,容器是映像的可运行实例。这就是为什么如果映像中有一个正在运行的容器,则无法删除该映像的原因。您只需要首先删除容器。

docker ps -a                # Lists containers (and tells you which images they are spun from)

docker images               # Lists images 

docker rm <container_id>    # Removes a stopped container

docker rm -f <container_id> # Forces the removal of a running container (uses SIGKILL)

docker rmi <image_id>       # Removes an image 
                            # Will fail if there is a running instance of that image i.e. container

docker rmi -f <image_id>    # Forces removal of image even if it is referenced in multiple repositories, 
                            # i.e. same image id given multiple names/tags 
                            # Will still fail if there is a docker container referencing image

Docker 1.13+更新[自2017年1月起]

在Docker1.13中,我们将每个命令重新组合到与之交互的逻辑对象下

基本上,上面的命令也可以更清楚地重写为:

docker container ls -a
docker image ls
docker container rm <container_id>
docker image rm <image_id>

此外,如果您想删除所有可以使用的内容:

docker system prune -a

警告!这将删除:

  • 所有停止的容器
  • 至少一个容器未使用的所有网络
  • 所有未使用的图像
  • 全部生成缓存
 类似资料:
  • 问题内容: 我想在Docker上删除容器,但是要删除时发生错误 我下一步删除容器之前,请参阅现有容器列表 我要删除该列表,即 “ training / webapp”, 但发生了一个错误 容器是否在图像中运行? 请帮忙 问题答案: 首先,删除容器名称 结果 删除第二部分,该部分在要删除的容器上列出 二,取出容器 结果 检查配件

  • 问题内容: 我无法删除失效的容器,重新启动Docker服务后,它将再次出现。 然后 然后,当我运行docker ps -a时,没有显示docker容器。 但是,当我重新启动docker服务时: 然后再次运行docker ps -a: 问题答案: 最有可能的是,当守护程序尝试清理容器时发生错误,并且他现在陷入了“僵尸”状态。 恐怕您唯一的选择是手动清理它: 哪里是你的驱动程序的名称(,,,或)。

  • 问题内容: 设置新的构建机器(CentOS 7,Docker CE 17.12.0-ce)时,我做了一个简单的测试: 效果很好,但是现在我无法删除Ubuntu映像。 任何容器都没有使用它(总之那不是错误): 我什至尝试了nuke-from-orbit方法: 并重新启动docker守护进程: 是什么赋予了?ubuntu映像是否存在并不重要,我只是不明白为什么我无法清理它。 更新资料 我尝试再次拉出图

  • 首先,我将引用另外两个对这个问题有部分答案的问题。 删除VM后从Azure中删除磁盘 如何删除Microsoft Azure存储中的租用blob 使用Azure Explorer,我可以删除blob和容器,但当我尝试删除存储帐户时,我出现了以下错误: 删除存储帐户“bitnamiWestusflwdmy”失败。无法删除存储帐户“bitnamiWestusflwdmy”:“存储帐户bitnamiWe

  • 我有很多运行docker容器的测试。每个都有一个卷。 如何知道需要删除的卷名? 例如: 手动停止并删除容器后,卷仍然存在。 我不想删除所有卷,因为其中一些卷仍在使用中。