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: filter docker image ls by name pattern to find one family of images

Docker
~/tips/tip-docker-image-ls-filter-reference

docker image ls --filter 'reference=nginx'

List only the images whose name or tag matches a pattern.

On a machine with a hundred images, docker image ls is a long scroll. The reference filter takes a name pattern and keeps only matching images.

docker image ls --filter 'reference=nginx'
docker image ls --filter 'reference=*:latest'
docker image ls --filter 'reference=ghcr.io/*/*'

The first shows every tag of nginx, the second everything tagged latest, the third every image from the GitHub registry. Add -q and you get IDs to feed into other commands, for example to remove all old builds of one project:

docker image rm $(docker image ls -q --filter 'reference=example/app:pr-*')

Run it without the rm part first and look at the list.

The pattern is matched like a file path, and that trips people up: * does not cross a slash. So *:latest matches wordpress:latest but skips ghcr.io/owner/app:latest, which needs */*/*:latest. Quote the pattern, or your shell may expand the stars into file names first. I find the before= and since= filters useful too, which take an image name and list images created before or after it.

Further reading: docker image ls: filtering

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