0

I am deleting the docker images by searching a pattern leaving only 2 docker images behind.

sudo docker rmi -f $(docker images | grep $search_docker_image | awk '{ print $3 }' | awk '!/'$base_docker_image_id'/ && !/'$recent_docker_image_id'/')

In the same command i want also delete the docker images which are older than 10 mins .Is it possible or is there any other way of achieving it.

Biswa
  • 1,501
  • 3
  • 11
  • 17

1 Answers1

-1

Docs

Filtering

The currently supported filters are:

until () - only remove containers, images, and networks created before given timestamp

label (label=, label==, label!=, or label!==) - only remove containers, images, networks, and volumes with (or without, in case label!=... is used) the specified labels.

As we can see, the possibilities for filtering are pretty broad, including regex. In this particular situation, you would use the timestamp to remove images older than 10 minutes. Ex:

docker image prune --filter "until=10m"

This removes all images older than 10 minutes. I have to ask, are you sure you want to remove images older than 10 minutes? Curious because it's usually containers which are ephemeral, not images. This command also works with containers (replace image with container).

justahuman
  • 607
  • 4
  • 13
  • 1
    thanx @justahuman . I think it works when you are doing prune only , but if I do docker image --filter "until=4h" it is throwing error - Error response from daemon: Invalid filter 'until' – Biswa Jun 08 '20 at 14:09