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

后端 未结 12 863
耶瑟儿~
耶瑟儿~ 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:25

    How about:

    ID=$(docker inspect --format="{{.Id}}" "$1")
    IMAGES=$(docker inspect --format="{{if eq \"$ID\" .Config.Image}}{{.Id}}{{end}}" $(docker images --filter since="$ID" -q))
    echo $(printf "%s\n" "${IMAGES[@]}" | sort -u)
    

    It'll print the child image id's, with the sha256: prefix.
    I also had the following, which appends the names:

    IMAGES=$(docker inspect --format="{{if eq \"$ID\" .Config.Image}}{{.Id}}{{.RepoTags}}{{end}}" $(docker images --filter since="$ID" -q))
    

    • ID= Gets the full id of the image
    • IMAGES= Gets all child images that have this image listed as an Image
    • echo... Removes duplicates and echos the results

提交回复
热议问题