How to get the list of dependent child images in Docker?

后端 未结 12 853
耶瑟儿~
耶瑟儿~ 2020-12-12 11:22

I\'m trying to remove an image and I get:

# docker rmi f50f9524513f  
Failed to remove image (f50f9524513f): Error response from daemon: conflict: unable to          


        
12条回答
  •  一向
    一向 (楼主)
    2020-12-12 12:04

    I've created a gist with shell script to print out descendant tree of a docker image, should anyone be interested in bash solution:

    #!/bin/bash
    parent_short_id=$1
    parent_id=`docker inspect --format '{{.Id}}' $1`
    
    get_kids() {
        local parent_id=$1
        docker inspect --format='ID {{.Id}} PAR {{.Parent}}' $(docker images -a -q) | grep "PAR ${parent_id}" | sed -E "s/ID ([^ ]*) PAR ([^ ]*)/\1/g"
    }
    
    print_kids() {
        local parent_id=$1
        local prefix=$2
        local tags=`docker inspect --format='{{.RepoTags}}' ${parent_id}`
        echo "${prefix}${parent_id} ${tags}"
    
        local children=`get_kids "${parent_id}"`
    
        for c in $children;
        do
            print_kids "$c" "$prefix  "
        done
    }
    
    print_kids "$parent_id" ""
    

提交回复
热议问题