Filter out multiple images via Docker CLI

Viewed 65

I am trying to list all the docker image IDs on my machine after "filtering out" two patterns.

pattern 1: docker/*
pattern 2: k8s.gcr.io/*.

This is the current list of images on my machine.

enter image description here

I am trying to get the final result to be

enter image description here

The final output would be only the "ID" of the python image.

How can I get the docker CLI to provide me this output? This solution should provide more IDs to me as the number of images that don't match the patterns above increase.

I tried to use grep but it provides me the entire output and not just the ID.

docker images | grep -v "docker\|k8s.gcr.io"
1 Answers

You could use awk to filter the id only from the docker images output:

docker images | grep -v "docker\|k8s.gcr.io\|REPOSITORY" | awk '{print $3}'

The $3 is the third column of next output, it will get 10fe7201ae97.

REPOSITORY                TAG           IMAGE ID         CREATED             SIZE
abc                       1             10fe7201ae97     11 days ago         4.41MB
Related