简体   繁体   English

即使没有容器正在运行,也无法删除图像

[英]Can not remove images even though no container is running

I had multiple stopped containers and images in my machine.我的机器中有多个停止的容器和图像。
I wanted to clean up and removed all containers:我想清理并移除所有容器:
docker ps -a returns nothing. docker ps -a返回任何内容。
I run docker rmi $(docker images -q) to remove the cached images but I get:我运行docker rmi $(docker images -q)来删除缓存的图像,但我得到:

Error response from daemon: conflict: unable to delete ... (must be forced) - image is referenced in multiple repositories来自守护进程的错误响应:冲突:无法删除...(必须强制) - 图像在多个存储库中被引用

What repositories is it talking about?它在谈论什么存储库?

You cannot remove images having multiple repositories without the force modifier, see Docker docs for more info.如果没有 force 修饰符,您将无法删除具有多个存储库的图像,请参阅 Docker文档以获取更多信息。

docker images
REPOSITORY                   TAG      IMAGE ID            CREATED           SIZE
repository/image-name        tag      a8e6fa672e89        10 days ago         344MB
repository2/image-name       tag      a8e6fa672e89        10 days ago         344MB

If you want to do it manually, instead of using the image id to remove the images, you must remove the repository/tag that you don't need using image names:如果您想手动执行此操作,而不是使用图像 ID 删除图像,您必须使用图像名称删除不需要的存储库/标签:

docker rmi a8e6fa672e89
Error response from daemon: conflict: unable to delete a8e6fa672e89 (must be forced) - image is referenced in multiple repositories

Remove the repository/tag you don't need:删除您不需要的存储库/标签:

docker rmi repository/image-name:tag
Untagged: repository/image-name:tag
Untagged: repository/image-name:tag@sha256:64b5a02e2bb3ee4d4b7c0982e8e2e5eb68bdfd0fb096fce22b6c030dafb53a33

(Repeat last step until only one repository/tag remains) And now you will be able to remove the image: (重复最后一步,直到只剩下一个存储库/标签)现在您将能够删除图像:

docker rmi a8e6fa672e89
Untagged: repository2/image-name:tag
Deleted: sha256:a8e6fa672e89b399bd3ac52b96c031e6816a69191d1fd7e6a1839fd643e3c751
Deleted: sha256:9861dd7b5783217515f571fdcfa6729e1e38af3ae9c971026e5a317b12fc5905

If you use the -f flag and specify the image's short or long ID, then rmi untags and removes all images that match the specified ID.如果使用 -f 标志并指定映像的短 ID 或长 ID,则 rmi 取消标记并删除与指定 ID 匹配的所有映像。

The "repositories" it is talking about is part of the first column of a docker images :它所谈论的“存储库”是docker images第一列的一部分:

docker images
REPOSITORY                   TAG      IMAGE ID            CREATED           SIZE
repository/image-name        tag      a8e6fa672e89        10 days ago         344MB
repository2/image-name       tag      a8e6fa672e89        10 days ago         344MB

(I take the samples which Gabriel showed in his answer) (我拿了加布里埃尔在他的回答中展示的样本)

Here we have two repositories: "repository" and "repository2".这里我们有两个存储库:“repository”和“repository2”。 As you also can see, both images have the same IMAGE ID.您还可以看到,两个图像具有相同的 IMAGE ID。

A docker images -q lists all available IMAGE ID's. docker images -q列出所有可用的图像 ID。 Thus if you want to remove an IMAGE ID which is referenced by two images you get the error that you have mentioned.因此,如果您想删除由两个图像引用的 IMAGE ID,则会出现您提到的错误。

Solution: You can remove the image by its name instead of its ID:解决方案:您可以通过名称而不是 ID 删除图像:

docker rmi repository/image-name:tag

You can clean up all containers.您可以清理所有容器。 First of all, you need to stop all containers with: docker stop $(docker ps -aq) .首先,您需要使用以下命令停止所有容器: docker stop $(docker ps -aq) Finally, remove all containers with: docker rm $(docker ps -aq) .最后,使用以下命令删除所有容器: docker rm $(docker ps -aq) You can do it all in one command docker rm $(docker stop $(docker ps -aq)) .您可以在一个命令docker rm $(docker stop $(docker ps -aq))

If you want to remove all containers data:如果要删除所有容器数据:

docker container prune
docker network prune
docker system prune
docker volume prune
docker builder prune

要强制删除一个 Docker 镜像,它指的是多个存储库,只需使用命令:

sudo docker rmi -f image_id

Error response from daemon: conflict: unable to delete 3472c3b5350b (must be forced) - image is referenced in multiple repositories Error response from daemon: conflict: unable to delete 3472c3b5350b (must be forced) - image is referenced in multiple repositories来自守护进程的错误响应:冲突:无法删除 3472c3b5350b(必须强制) - 映像在多个存储库中引用 来自守护进程的错误响应:冲突:无法删除 3472c3b5350b(必须强制) - 映像在多个存储库中引用

If this error is coming first untag the image and then it can be deleted.如果此错误首先出现,请取消标记图像,然后将其删除。 This can be done by using thee following command.这可以通过使用以下命令来完成。 docker rmi :<image_tag> docker rmi :<image_tag>

如果您确定要删除所有图像,可以使用以下命令:

docker images | awk '{print $1":"$2}' | egrep -E 'REPOSITORY|TAG' | xargs -n1 docker rmi

to delete a single record : sudo docker rmi -f <image_name>删除单个记录:sudo docker rmi -f <image_name>

to delete all images:删除所有图像:
sudo docker rmi -f $(sudo docker images -a -q)须藤泊坞窗 rmi -f $(须藤泊坞窗图像 -a -q)

The "-f" parameter is important “-f”参数很重要

 docker rmi `docker images --format="{{.Repository}}:{{.Tag}}"`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使有 dylib 符号也无法读取 - Can't read even though there is dylib symbol Safari 收藏夹图标显示为透明图像,即使它们不是 - Safari favorites icons are displayed as transparent images even though they're not 即使正确安装,也无法在 Jupyter notebook 中导入 pygame - Can not import pygame in Jupyter notebook even though it is installed correctly 即使django已启动并正在运行,Django测试页仍会返回404 - Django test-page returns 404 even though django is up and running 无法连接到在Docker容器中运行的oracledb - can not connect to oracledb running in a docker container 即使有文件夹也没有这样的文件或目录 - No such file or directory even though there is a folder MacOS Mojave:即使我在回显 $PATH 时可以看到路径,也找不到命令 - MacOS Mojave: Command not found even though I can see the path when I echo $PATH Groovy为什么即使在我的PATH上也找不到该程序? - Why can't Groovy find this program even though it's on my PATH? 无法从Mac切换到iOS,即使从iOS切换到Mac也能正常工作 - Can't handoff from Mac to iOS, even though handoff from iOS to Mac works fine 即使我安装了 JRE,也无法打开.jnlp 文件 - Can't open .jnlp file even though I have a JRE installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM