CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Docker / docker images

docker images

List, filter and clean up local images

Beginnerimagesstorageessential

docker images (docker image ls) lists the images in the local store: name and tag, image ID, size on disk and whether a container uses them. It's how you check what's been built or pulled, spot untagged leftovers, and decide what to remove.

Syntaxdocker images [OPTIONS] [REPOSITORY[:TAG]] (same as docker image ls)

Watch it run

You've just built and pulled a few images and want to see what's stored locally and how big it is.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
docker images

Docker 29's view, sorted by name. DISK USAGE is the unpacked size on disk; CONTENT SIZE is the compressed layers, roughly what a pull downloads. U marks images used by at least one container, so they can't be removed.

Anatomy of a command

$
commanddocker images

List images in the local image store. Same as docker image ls.

How it works

The CLI calls GET /images/json. An image is a manifest (a JSON list of layer digests plus a config blob) stored by content: its ID is the sha256 of that config or, with the containerd image store that is the default on new Docker 29 installs, of the manifest or multi-platform index. A tag such as shop-api:1.4.0 is only a name pointing at that digest, so one image can have many tags, and moving a tag to a new build leaves the old image <untagged> (dangling). Layers are shared: ten images built FROM node:22-alpine store its layers once, which is why adding up the SIZE column overstates real disk use. docker system df gives the true total.

Options you'll actually use

-a, --allAlso show intermediate images (legacy builder)
-q, --quietOnly image IDs
-f dangling=trueOnly untagged images left behind by rebuilds
-f reference=PATTERNOnly names matching a glob, like 'shop-api:*'
-f before=IMG / since=IMGImages created before or after another image
--digestsAdd the content digest (sha256:...) column
--format TEMPLATECustom columns, or json
--no-truncFull sha256 IDs
--treeShow each platform of a multi-platform image (experimental)

Common mistakes

Adding up the SIZE column to explain disk usage

Layers are shared between images, so the same base layers are counted once per image.

docker system df (and docker system df -v for per-image shared vs unique size)
docker rmi $(docker images -q) to 'clean up'

Tries to delete every image, fails noisily on the ones in use and forces re-pulls of the rest.

docker image prune (dangling only), or docker image prune -a --filter until=168h
Assuming nginx:latest on two hosts is the same image

Tags are mutable pointers; each host has whatever latest meant when it pulled.

Compare digests (docker images --digests) or deploy by digest

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    List only the IDs of the dangling images on this host.

  2. 2

    Write a command that prints each local image as 'name:tag size', one per line, for all shop-api tags.

  3. 3

    Explain this line from docker images: 'shop-api:1.4.0 4b1e7d2c9a03 212MB 58.3MB U'. What do the two sizes and the U mean?

Related commands

docker buildBuild an image from a Dockerfiledocker pullDownload an image from a registrydocker system pruneReclaim disk space from unused Docker datadocker rmRemove containers
Previousdocker psNextdocker pull
Linux / Docker / docker images

docker images

List, filter and clean up local images

Beginnerimagesstorageessential

docker images (docker image ls) lists the images in the local store: name and tag, image ID, size on disk and whether a container uses them. It's how you check what's been built or pulled, spot untagged leftovers, and decide what to remove.

Syntaxdocker images [OPTIONS] [REPOSITORY[:TAG]] (same as docker image ls)

Watch it run

You've just built and pulled a few images and want to see what's stored locally and how big it is.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
docker images

Docker 29's view, sorted by name. DISK USAGE is the unpacked size on disk; CONTENT SIZE is the compressed layers, roughly what a pull downloads. U marks images used by at least one container, so they can't be removed.

Anatomy of a command

$
commanddocker images

List images in the local image store. Same as docker image ls.

How it works

The CLI calls GET /images/json. An image is a manifest (a JSON list of layer digests plus a config blob) stored by content: its ID is the sha256 of that config or, with the containerd image store that is the default on new Docker 29 installs, of the manifest or multi-platform index. A tag such as shop-api:1.4.0 is only a name pointing at that digest, so one image can have many tags, and moving a tag to a new build leaves the old image <untagged> (dangling). Layers are shared: ten images built FROM node:22-alpine store its layers once, which is why adding up the SIZE column overstates real disk use. docker system df gives the true total.

Options you'll actually use

-a, --allAlso show intermediate images (legacy builder)
-q, --quietOnly image IDs
-f dangling=trueOnly untagged images left behind by rebuilds
-f reference=PATTERNOnly names matching a glob, like 'shop-api:*'
-f before=IMG / since=IMGImages created before or after another image
--digestsAdd the content digest (sha256:...) column
--format TEMPLATECustom columns, or json
--no-truncFull sha256 IDs
--treeShow each platform of a multi-platform image (experimental)

Common mistakes

Adding up the SIZE column to explain disk usage

Layers are shared between images, so the same base layers are counted once per image.

docker system df (and docker system df -v for per-image shared vs unique size)
docker rmi $(docker images -q) to 'clean up'

Tries to delete every image, fails noisily on the ones in use and forces re-pulls of the rest.

docker image prune (dangling only), or docker image prune -a --filter until=168h
Assuming nginx:latest on two hosts is the same image

Tags are mutable pointers; each host has whatever latest meant when it pulled.

Compare digests (docker images --digests) or deploy by digest

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    List only the IDs of the dangling images on this host.

  2. 2

    Write a command that prints each local image as 'name:tag size', one per line, for all shop-api tags.

  3. 3

    Explain this line from docker images: 'shop-api:1.4.0 4b1e7d2c9a03 212MB 58.3MB U'. What do the two sizes and the U mean?

Related commands

docker buildBuild an image from a Dockerfiledocker pullDownload an image from a registrydocker system pruneReclaim disk space from unused Docker datadocker rmRemove containers
Previousdocker psNextdocker pull