Docker old images cleanup?
The output of
sudo docker images shows images that were created ages ago, I don’t see any use for them,
sudo docker system prune does not remove them either.
How can I easily delete old images? Do I have to write a script to conditionally delete based on
date created within the output of
One Solution collect form web for “Docker old images cleanup?”
I don’t think you can filter images by created date, but you can use another image as a reference of time.
The flag (
before shows only images created before the image with given id or reference.
For example, having these images:
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE image1 latest eeae25ada2aa 4 minutes ago 188.3 MB image2 latest dea752e4e117 9 minutes ago 188.3 MB image3 latest 511136ea3c5a 25 minutes ago 188.3 MB
before (image1) would give:
$ docker images --filter "before=eeae25ada2aa" REPOSITORY TAG IMAGE ID CREATED SIZE image2 latest dea752e4e117 9 minutes ago 188.3 MB image3 latest 511136ea3c5a 25 minutes ago 188.3 MB
To Remove images before image1(eeae25ada2aa)
$ docker rmi $(docker images --filter "since=511136ea3c5a" -q) dea752e4e117 511136ea3c5a