How to remove unused Docker images?
Docker images can quickly consume a lot of available disk space. This tutorial shows how to remove unused docker images quickly, as well as what are other clean-up operations worth running once in a while.
Removing dangling docker images
A dangling docker image is an image that is not tagged and is not used by any container. Below command removes all such images.
docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Removing unused docker images
An unused docker image is an image that is not used by any container. Below command removes all such images.
docker image prune -a
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
Removing all docker images with a specific label
Sometimes you want to prune images with a specific label only. You can specify such a label with the --filter
option.
docker image prune -a --filter "label=<key>=<value>"
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
You can also use !=
operator to specify all docker image without given label.
docker image prune -a --filter "label!=<key>=<value>"
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
Removing docker images older than 1 day
If you want to remove all unused and dangling images created more than 24 hours ago, here’s how to do it:
docker image prune -a --filter "until=24h"
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y