3

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?

Eka
  • 10,884
  • 31
  • 98
  • 166
  • 1
    There is no redundant image layer in your case. The two new images would share one image layer(OS image you built at first). So the disk usage is not 3GB, which you could check with `du -sh`. – Light.G Sep 28 '18 at 03:31
  • could you list down the commands u ran till you created the child image? – Blue Clouds Sep 28 '18 at 04:42

2 Answers2

4

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

Abhi
  • 41
  • 2
  • 1
    This comment is useful for deleting images which have dependent child images, thanks this helped me. – Shaphan Dec 30 '19 at 09:32
3

Container is formed with different docker image layers as follows.

So when you add new things to container, and finally make it as another image, you just add a new layer upon the original image layers, so no need to delete the base image layers, they are shared by your new containers. Also, only with these base image layers, your new image with its own layers can be possible to form a new container.

enter image description here

atline
  • 16,106
  • 12
  • 44
  • 65
  • But still, he would suffer the issue(leaving multiple useless images which only useful for the next image built based on it). He may only use the last image, perhapsly. – Light.G Sep 28 '18 at 03:37