1

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 docker images?

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
  • Have you checked out [this](https://stackoverflow.com/questions/17236796/how-to-remove-old-docker-containers) and [this](https://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images) questions? – DarkCygnus Jun 26 '17 at 17:48
  • 2
    I agree, this is a duplicate. The referenced questions are specifically about container but have examples for images in them (as well as information about the newer `prune` command). – Andy Shinn Jun 26 '17 at 17:50
  • @scott Stensland this is not a duplicate question, in the docker world images and container are different – Hemerson Varela Jun 26 '17 at 18:22
  • The two top answers on https://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images do not solve the issue. But yes I'd agree it's a duplicate question. – Chris Stryczynski Jun 26 '17 at 19:40

1 Answers1

1

I don't think you can filter images by created date, but you can use another image as a reference of time.

The flag (-f or--filter) with 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

Filtering with 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 
Hemerson Varela
  • 24,034
  • 16
  • 68
  • 69