我有以下图片:

alex@alexvps:~$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>              <none>              70c0e19168cf        5 days ago          1.069 GB
<none>              <none>              c2ce80b62174        8 days ago          399.2 MB
<none>              <none>              60afe4036d97        8 days ago          325.1 MB

当我试图删除其中一个时,我会得到:

alex@alexvps:~$ sudo docker rmi 60afe4036d97
Error: Conflict, 60afe4036d97 wasn't deleted
2014/01/28 00:54:00 Error: failed to remove one or more images

我该如何移除它们?为什么会有这样的冲突?


当前回答

在Bash中:

for i in `sudo docker images|grep \<none\>|awk '{print $3}'`;do sudo docker rmi $i;done

这将删除所有名称为“<none>”的图像。我发现那些图片是多余的。

其他回答

首先必须停止/删除在映像上创建的所有不必要的容器。

看看:如何删除旧Docker容器。

之后使用@marcell溶液。

我已经找到了一个解决方案与Powershell脚本,这将为我。

该脚本首先停止所有容器,然后删除所有容器,然后删除由用户命名的图像。

看这里http://www.devcode4.com/article/powershell-remove-docker-containers-and-images

可能的原因: 原因可能是当前正在运行的容器正在使用该映像。在这种情况下,你可以列出正在运行的容器,停止相关的容器,然后删除图像:

docker ps
docker stop <containerid>
docker rm <containerid>
docker rmi <imageid>

如果你不能通过docker ps找到容器,你可以使用它列出所有已经退出的容器并删除它们。

docker ps -a | grep 60afe4036d97
docker rm <containerid>

注意:注意不要一次性删除所有已退出的容器,以免使用仅限卷容器。它们保持在Exit状态,但包含有用的数据。

从Docker开始。1.13.0(2017年1月)有系统剪枝命令:

$ docker system prune --help

Usage:  docker system prune [OPTIONS]

Remove unused data

Options:
-a, --all     Remove all unused images not just dangling ones
-f, --force   Do not prompt for confirmation
    --help    Print usage

我在这条命令中找到了答案:

docker images --no-trunc | grep none | awk '{print $3}' | xargs docker rmi

当我删除一些正在使用的图像时,我遇到了你的问题,我没有意识到(使用docker ps -a)。