Having unnecessary images lying around our host
can be quite a bother. Firstly, it consumes a lot
of disk space and having multiple version of
similar images can cause confusions nonetheless.
Let's list out our available images.
[No Audio]
Just take a look, the list is already exhaustive. Time to
narrow it down a bit to keep things neat and tidy.
First, let's use rm or remove command. We will
remove an image with 1-alpine perl tag.
As you may remember, these images were pulled as a
stack of layered intermediate images, so they will
also be removed similarly.
All of the intermediate images along with the resultant image will be
removed from our host. Just to verify how did our command do,
let's get another list of images
and we shouldn't find any image with 1-alpine perl tag.
Another way to write image rm, is to
simply write rmi and follow it by image id.
When we use image id instead of image tag, all images
containing that id will be removed.
Here, 1-alpine and alpine variants of nginx image
will be affected by this command.
On the other hand, such an operation involving id of the image
which is used more than once cannot be performed normally.
That's why we are getting this error and
the suggestion to remove them forcefully, let's do so.
We will use the same command with --force tag.
As you may notice, all of the images with this id
will be freed from that tag
and they will be removed along with their intermediate images.