Reputation: 15000
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?
Upvotes: 5
Views: 9207
Reputation: 71
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
Upvotes: 7
Reputation: 31564
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.
Upvotes: 2