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,
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.
1docker rmi
To get the list of images,
1docker images
Using the image id, you can remove it.
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
1docker rmi $(docker images --filter=reference='<IMAGENAME>' --format "{{.ID}}")
For Example,
To remove an image named docker-healthcheck
. i am using the command,
1docker rmi -f $(docker images --filter=reference='docker-healthcheck' --format "{{.ID}}")
To remove all images from the machine.
1docker rmi $(docker images -q)
it will remove all the images at once.
To remove untagged images from docker. you can use options --dangling=true
which will remove the untagged images.
1docker images -f "dangling=true"
Above command lists down all the untagged images.
1$ docker rmi $(docker images -f "dangling=true" -q) --force
it removes all the images which are untagged.
To remove unused images from docker. you can use a single command to remove the unused images.
1docker image prune
it will remove usused images.
1docker image --all prune
above command remove all the unused images from docker.
No spam, ever. Unsubscribe anytime.