我在努力

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


当前回答

对我来说有用的是使用REPOSITORY:TAG组合而不是IMAGE ID。

当我试图用命令docker rmi < image ID>删除一个没有与此映像关联的容器的docker映像时,我得到了这样的消息:

$ docker rmi 3f66bec2c6bf
Error response from daemon: conflict: unable to delete 3f66bec2c6bf (cannot be forced) - image has dependent child images

当我使用命令docker rmi RPOSITORY:TAG时,我可以成功删除

$ docker rmi ubuntu:18.04v1
Untagged: ubuntu:18.04v1

其他回答

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

#!/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: b721d1cdaac7

 docker rmi b721d1cdaac7 -f

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

删除所有子映像

docker image rm $(docker images --filter since=b721d1cdaac7 -q) -f

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

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

然后调用command:

docker rmi {sub_image_id} 

sub_image_id为从属图像ID

只需简单地使用:

docker rmi <image:tag> -f

例如:

docker rmi ubuntu:latest -f 

将删除标签名为latest的映像名称ubuntu, -f是强制删除。

这对我很有效

如果你想取消Docker图像的标签

docker rmi <rep:tag>

如果你想删除Docker镜像

docker image rm <image_id>

例如:输入docker image ls来显示图像的信息

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
python              3.6            60f85556d5d2        4 days ago          174MB

Docker rmi python:3.6

Docker镜像rm 60f85556d5d2