How to remove docker image - Docker tips and tricks
How to remove docker image - Docker tips and tricks
This guide will cover everything you need to know about removing docker images from the local machine or from the registry. there are several ways to remove the docker images with command. let’s see some tricks to do that.
if you’re new to the world of docker, i would suggest you to checkout these articles,
Docker remove image - ways to do
There are different ways to remove the docker image. you can remove by id, name, and tag. let’s see each command one by one.
docker rmi
is the command to remove the images from the docker. you can identify the specific image to remove or remove all at once.
docker rmi
docker remove image by id
To get the list of images,
docker images
Using the image id, you can remove it.
docker remove image by name
you can remove docker image by name. there’s a trick to do that, you need to select the image name with filter and format options in docker images
docker rmi $(docker images --filter=reference='<IMAGENAME>' --format "{{.ID}}")
For Example,
To remove an image named docker-healthcheck
. i am using the command,
docker rmi -f $(docker images --filter=reference='docker-healthcheck' --format "{{.ID}}")
docker remove all image
To remove all images from the machine.
docker rmi $(docker images -q)
it will remove all the images at once.
docker remove image with none tag
To remove untagged images from docker. you can use options --dangling=true
which will remove the untagged images.
docker images -f "dangling=true"
Above command lists down all the untagged images.
$ docker rmi $(docker images -f "dangling=true" -q) --force
it removes all the images which are untagged.
Docker remove unused images
To remove unused images from docker. you can use a single command to remove the unused images.
docker image prune
it will remove usused images.
docker image --all prune
above command remove all the unused images from docker.