我在努力

docker rmi c565603bc87f

错误:

来自守护进程的错误响应:冲突:无法删除c565603bc87f (不能强制)- image有依赖的子映像

所以我不能用-f标记删除image。如何删除图像,然后所有的孩子?

Linux和docker版本:

uname - Linux goracio-pc 4.4.0-24-generic #43-Ubuntu SMP Wed Jun 8 19:27:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

码头工人版本 客户: 版本:1.11.2 API版本:1.23 Go版本:go1.5.4 Git提交:b9f10c9 建成:2016年6月1日星期三22:00:43 OS /拱:linux / amd64

服务器: 版本:1.11.2 API版本:1.23 Go版本:go1.5.4 Git提交:b9f10c9 建成:2016年6月1日星期三22:00:43 OS /拱:linux / amd64


当前回答

下面是一个脚本,用于删除一个图像和依赖于它的所有图像。

#!/bin/bash

if [[ $# -lt 1 ]]; then
    echo must supply image to remove;
    exit 1;
fi;

get_image_children ()
{
    ret=()
    for i in $(docker image ls -a --no-trunc -q); do
        #>&2 echo processing image "$i";
        #>&2 echo parent is $(docker image inspect --format '{{.Parent}}' "$i")
        if [[ "$(docker image inspect --format '{{.Parent}}' "$i")" == "$1" ]]; then
            ret+=("$i");
        fi;
    done;
    echo "${ret[@]}";
}

realid=$(docker image inspect --format '{{.Id}}' "$1")
if [[ -z "$realid" ]]; then
    echo "$1 is not a valid image.";
    exit 2;
fi;
images_to_remove=("$realid");
images_to_process=("$realid");
while [[ "${#images_to_process[@]}" -gt 0 ]]; do
    children_to_process=();
    for i in "${!images_to_process[@]}"; do
        children=$(get_image_children "${images_to_process[$i]}");
        if [[ ! -z "$children" ]]; then
            # allow word splitting on the children.
            children_to_process+=($children);
        fi;
    done;
    if [[ "${#children_to_process[@]}" -gt 0 ]]; then
        images_to_process=("${children_to_process[@]}");
        images_to_remove+=("${children_to_process[@]}");
    else
        #no images have any children. We're done creating the graph.
        break;
    fi;
done;
echo images_to_remove = "$(printf %s\n "${images_to_remove[@]}")";
indices=(${!images_to_remove[@]});
for ((i="${#indices[@]}" - 1; i >= 0; --i)) ; do
    image_to_remove="${images_to_remove[indices[i]]}"
    if [[ "${image_to_remove:0:7}" == "sha256:" ]]; then
        image_to_remove="${image_to_remove:7}";
    fi
    echo removing image "$image_to_remove";
    docker rmi "$image_to_remove";
done

其他回答

找到图像id和父id的所有图像之后创建的图像问题如下:

docker inspect --format='{{.Id}} {{.Parent}}' $(docker images --filter since=<image_id> -q)

然后调用command:

docker rmi {sub_image_id} 

sub_image_id为从属图像ID

你可以这样做:

➜~出汗决议rmi 4ed13257bb55 + Deleted: sha256:4ed13257bb5512b975b316ef482592482ca54018a7728ea1fc387e873a68c358 Deleted: sha256:4a478ca02e8d2336595dcbed9c4ce034cd15f01229733e7d93a83fbb3a9026d3 Deleted: sha256:96df41d1ce6065cf75d05873fb1f9ea9fed0ca86addcfcec7722200ed3484c69 Deleted: sha256: d95efe864c7096c38757b80fddad12819fffd68ac3cc73333ebffaa42385fded

我有这个问题,这里没有一个简短的答案,即使在上面@tudor提到的页面。我想在这里分享一下我是如何摆脱这些图像的。我想出了一个想法,从属图像必须是>=父图像的大小,这有助于识别它,以便我们可以删除它。

我按大小列出了这些图片,看看是否能发现其中的相关性:

docker images --format '{{.Size}}\t{{.Repository}}\t{{.Tag}}\t{{.ID}}' | sort -h -r | column -t

它所做的是使用docker中的一些特殊格式来首先定位图像大小列,然后以相反的顺序运行人类可读的排序。然后恢复易于阅读的列。

然后我查看<none>容器,并将列表中的第一个容器与类似的大小匹配。我在该图像上执行了一个简单的docker rmi <image:tag>,所有<none>子图像都随它而去。

所有子映像的问题映像实际上是我第一次开始使用docker时使用的该死的myrepo/getstart -lab映像。这是因为我从第一个创建链的测试图像中创建了一个新图像。

希望这能在某种程度上帮助到其他人。

在某些情况下(比如我的例子),您可能试图通过指定具有多个您没有意识到存在的标记的图像id来删除图像,其中一些可能被其他图像使用。在这种情况下,您可能不想删除图像。

如果你有一个冗余标签的情况,如这里所述,而不是docker rmi <image_id>使用docker rmi <repo:标签>在你希望删除的冗余标签上。

如果在公司代理后面,请确保您没有遇到速率限制错误。

如果你碰巧安装了公司代理,并且使用Windows,你可能想尝试一下这个简单的修复方法。我在这里找到了一些有用的回答。然而,即使在运行docker映像修剪和其他命令之后,我仍然发现了一个可爱的错误(以及根本原因),这是之前掩盖的:“toomanyrequests: You have reached your pull rate limit…”

Fix.

打开Windows终端/DOS提示符,输入:

ipconfig /发行 [...] ipconfig /恢复

这可能会帮你省下和IT部门的电话/罚单。;)