Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete parent image after committing to a child image in docker?

I installed a docker image with OS of about a GB in my system and then I updated and installed additional software which pushed the size to almost 2 GB. I used this container to create a new child image by docker commit <cont-id> <child-name>. Now I have two docker images with both parent and child images totalling to 3 GB. As I have a redundant 1 GB of parent image I want to remove it.

Parent  image 1 GB
Child   image 2 GB

I tried to keep the child image and tried to remove parent image by docker rmi -f <image-id> but its giving this error

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

Then tried this solution, I tried sudo docker images --filter "dangling=true" -q --no-trunc but returned nothing and also tried docker system prune which shows 0 GB.

I am also planning to install other programs to the OS inside docker and thus want to spawn new child images from existing child images. I searched everywhere and there is no good solution to delete a parent image in docker and the reason I read because of some parent layers being used by child images. Is there no way to delete a parent image in docker after spawning a new child image?

like image 807
Eka Avatar asked Jan 01 '23 19:01

Eka


1 Answers

Instead of docker rmi <image_id> use docker rmi <repo:tag>

You can get the repo and tag, from the output of docker images

The answer by @atline is the theoretical part of the answer. Mentioned here is the way to delete the previous versions of the same base image, given that the child (or lower layers) won't be deleted/affected

credits :https://stackoverflow.com/a/50650745/5711056

like image 50
Abhi Avatar answered Jan 16 '23 22:01

Abhi