Log in

Video Lesson: List images in Docker

List images in Docker

Learn how to list Docker images, view details by digest, and retrieve image IDs using Docker CLI commands.


Lesson Content

Once you have a lot of docker images downloaded to your machine, you’ll need a way to recall what image IDs they use and other related info.

The Docker command to do this is:

docker image ls

This will display a table of all currently downloaded images, and there could be many. This is a common task, so Docker also aliases this command to docker images:

$ docker images

REPOSITORY    TAG          IMAGE ID        CREATED         SIZE
nginx         latest       605c77e624dd    2 weeks ago     141MB
redis         7.2          7614ae9453d1    3 months ago    113MB
ubuntu        22.04        b6548eacb063    4 months ago    77.8MB
node          20-alpine    1a0c9f2e3d4b    5 days ago      111MB

The fields are pretty self-explanatory, but here's something useful to know: the Size column includes all the space taken up by the image and all of its parent images.

You can also pass in an argument to find specific images, for example all Node images:

$ docker images nginx

REPOSITORY   TAG           IMAGE ID       CREATED        SIZE
nginx        alpine        35f3cbee4fb7   3 weeks ago    52.9MB
nginx        1.29          47ef8710c9f5   3 weeks ago    198MB
nginx        1.27-alpine   cedb667e1a7b   7 months ago   49.4MB
nginx        1.24          9eccb584dbf2   2 years ago    135MB

List Docker images by digest

The “digest” is a hash that uniquely identifies a specific image, and it’s possible to run an image linked to a specific digest.

If you need the value of images matching a specific digest value, just pass in the --digests flag (which you can add to other arguments as well):

$ docker images nginx --digests

REPOSITORY    TAG     DIGEST                                                                     IMAGE ID        CREATED        SIZE
nginx         1.29    sha256:33e0bbc7ca9ecf108140af6288c7c9d1ecc77548cbfd3952fd8466a75edefe57    47ef8710c9f5    3 weeks ago    198M
nginx         1.24    sha256:f6daac2445b0ce70e64d77442ccf62839f3f1b4c24bf6746a857eff014e798c8    9eccb584dbf2    2 years ago    135MB

When we execute this, we will see a SHA hash that relates to this specific image. You can think of this hash as a reference to a snapshot of an image at a specific point in time.

This is incredibly useful when you need to guarantee the exact same Docker image runs on multiple machines. It's Docker's answer to that classic developer headache: "well, it works on my machine!”

Return only Docker image IDs

It’s also possible that you’ll just need to grab the IDs of Docker images, and nothing else. This is very useful for piping or passing the image IDs into another command.

We can do this with the -q (or --quiet) option:

docker images -q

For example, we can pipe the output to the wc -l command, which uses the “word count” tool to grab the number of lines, essentially outputting the total count of Docker images:

docker images -q | wc -l

This command is particularly useful within bash scripts, as you can do something like checking if a specific image exists within a conditional:

docker images nginx -q | grep -q . && echo "exists"

The -q flag silences the output from grep, which makes the result of the echo command the only output.