Skip to content

Instantly share code, notes, and snippets.

@Siva-Charan
Last active October 9, 2022 11:18
Show Gist options
  • Save Siva-Charan/db7bd84ad2ca2b0779d87a75e6bb4176 to your computer and use it in GitHub Desktop.
Save Siva-Charan/db7bd84ad2ca2b0779d87a75e6bb4176 to your computer and use it in GitHub Desktop.
Docker: How to find the dependent child images?

Find the dependent child images on Docker

When you try to remove the docker image with the following command

docker rmi 6795374be8c1

Sometimes you might be facing below error:

Error response from daemon: conflict: unable to delete 6795374be8c1 (cannot be forced) - image has dependent child images

Below is the Docker command line used to find the dependent child images

Format:

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

Example:

docker inspect --format='{{.Id}} {{.Parent}}' $(docker images --filter since=6795374be8c1 -q)

Result:

sha256:1d1f94c972fc8d75a34135f9ff551617680c508f7ad17efda09048b4e805g1w3

Here sha256:1d1f94c972fc8d75a34135f9ff551617680c508f7ad17efda09048b4e805g1w3, the bold value is your dependent child image

@leandrodeliver
Copy link

That didn't work. "docker inspect" requires at least 1 argument.

@Davidrjx
Copy link

@leandrodeliver replace since with your own existing image id and note sudo priviledge

@ankitkotnala
Copy link

try to delete the image with repository name instead of image id like
docker rmi
OR
docker image rm

@gidiyorum
Copy link

first, you must delete the images in which that image was used previously.
Let me explain that : you have "your-package: latest" and it was inherited from PHP:7-0-apache
if you want to delete "php:7-0-apache" first you must delete "your-package: latest" afterward your desired PHP image

@nlrahimi
Copy link

Thanks for sharing the solution, though it did not work for me with REPOSITORY name or IMAGE ID, for the same problem that inspect needs at least one argument. (I am a sudo user of my ubuntu system)

@marcelkohl
Copy link

If you got the message that "docker inspect" requires at least 1 argument means that the docker images --filter didn't returned any image.

@yogithesymbian
Copy link

➜  ~ docker image ls -a
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
yogimaker                latest              9e26907ab97c        2 days ago          1.59GB
<none>                   <none>              1334b5f7a1c8        2 days ago          1.55GB
as                       latest              46fd53ef8b95        2 days ago          1.54GB
kalilinux/kali-rolling   latest              14da2d1801b5        7 days ago          114MB
tensorflow/tensorflow    latest              539d0e818045        5 weeks ago         1.54GB
hello-world              latest              bf756fb1ae65        8 months ago        13.3kB
➜  ~ docker inspect --format='{{.Id}} {{.Parent}}' $(docker images --filter since=46fd53ef8b95 -q)
sha256:9e26907ab97cb6aa43fbbcd9d48c8631810af77971fe2e2e843b646a1c7ca4de sha256:1334b5f7a1c8aaa4c10dc3c7792f419776a667e29abbd0134732e92ad26d799d
➜  ~ 

so when i added new feature for example upgrade version of application like pip
before my pip version example 1
then i upgrade to version example 4
this always make new container and new image .
so this normal for docker ? and consume memory ??? or how to manag ?

@yogithesymbian
Copy link

i want to delete image what i dont use, but the image have child where the child image is use...

@nonunicorn
Copy link

docker inspect --format='{{.Id}} {{.Parent}}' $(docker images --filter since=6795374be8c1 -q)
This will also return not dependent images, but that were created since specified one was. You have to additionally filter with parent id like here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment