brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker image prune -a --filter until= only removes old images

Docker
~/tips/tip-docker-image-prune-until

docker image prune -a --filter "until=240h"

Removes only unused images older than a set age instead of every unused image.

A bare docker image prune -a removes every image that no container uses. That includes the one you pulled five minutes ago for tomorrow.

You can limit it by age with a filter. Docker accepts a Go duration, a date or a timestamp.

docker image prune -a --filter "until=240h"

That removes unused images created more than ten days ago and leaves the fresh ones alone. Without -a it only touches dangling images, which are the untagged leftovers of rebuilds. Prune asks for confirmation unless you add -f, and I would keep the prompt for a first run.

Run it by hand first and read what it lists. Since an unused image is one without a container, stopped containers still protect their image, so remove those first if you want the space back.

The caveat is the word created. The filter looks at when the image was built, not when you pulled it. An image pulled today that the maintainer built a month ago still matches. Docker also warns about dangling images in the prompt even when a filter is set, so do not let that text scare you.

Further reading: docker image prune, On this site: run docker system df before you prune anything, On this site: a .dockerignore file makes builds faster and images smaller

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link