I'm building images on a small server and spinning them up with docker-compose.
When it's disk gets full I run docker prune -a
so all the stopped containers, dangling image are cleaned out.
But I'd like to keep one or two recent images in case I need to roll back quickly.
The docker prune documentation says --filter until=<timestamp>
. But the timestamps from the previous images could be days, weeks or months old.
Then suggested method for pruning by date is:
a) find the timestamp by listing the images with this format
docker images --format 'table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedAt}}\t{{.Size}}'
which produces
REPOSITORY TAG IMAGE ID CREATED AT SIZE
foo latest 2f287ac753da 2017-01-04 13:42:23 -0800 PST 3.98 MB
alpine latest 88e169ea8f46 2016-12-27 10:17:25 -0800 PST 3.98 MB
busybox latest e02e811dd08f 2016-10-07 14:03:58 -0700 PDT 1.09 MB
How can I automatically select the second created at
timestamp in the list it produces?
...to then pass it as a variable into
b)
docker image prune -a --force --filter "until=<2rd timestamp from list>"
Is there an way to use awk ? Is there another way to leave an extra image ?