Sub topic 4
Reading sizes, instructions, and <missing> IDs
This chapter assumes you can build and run images, read a simple Dockerfile, and use a Linux shell. It also assumes you know that an image is a stack of layers. Here you will learn to read each column of docker history output and to avoid the common misreadings.
Build the example image
Use the wasteful Dockerfile from the spine. Save it next to a data.tar file, then build and list the layers.
FROM debian:bookworm-slim
RUN apt-get update
RUN apt-get install -y curl
COPY data.tar /tmp/data.tar
RUN tar -xf /tmp/data.tar -C /opt
RUN rm /tmp/data.tardocker build -t demo:wasteful .
docker history demo:wastefuldocker history prints one row per layer, newest first. The bottom row is the base image, and the top row is your last instruction.
The columns
| Column | Meaning |
|---|---|
| IMAGE | The ID of the image that ends at this layer, or `<missing>` |
| CREATED | How long ago the layer was made |
| CREATED BY | The instruction that produced the layer, usually shortened |
| SIZE | The bytes this layer adds |
| COMMENT | Optional note, often empty |
Read the table from the bottom up to follow the build in order. Each row depends on the rows below it.
Reading the SIZE column
SIZE is the size of that layer alone. It is not a running total. The image size is roughly the sum of all rows.
Instructions that only change metadata, such as ENV, CMD, WORKDIR, EXPOSE and LABEL, show 0B. They record configuration and add no files.
In the example, expect these patterns:
RUN apt-get updateshows tens of megabytes, because the package lists in/var/lib/apt/listsare written into the layer.RUN apt-get install -y curladds the packages themselves.COPY data.tar /tmp/data.taradds the full size ofdata.tar.RUN tar -xf ...adds the extracted files, so the data now exists twice.RUN rm /tmp/data.tarshows0Bor a few bytes.
The last point is the one that surprises people. The rm layer is small, but the image did not shrink. A layer is a set of changes, and deleting a file adds a marker that hides it. The file's bytes stay in the earlier COPY layer. Reading SIZE alone would suggest rm is harmless, so a 0B row after a large layer is a hint to look closer.
Reading CREATED BY
By default, long commands are cut off with .... Use --no-trunc to see the whole instruction, which helps when a RUN line chains many commands.
docker history --no-trunc demo:wastefulYou will see that RUN lines appear as /bin/sh -c apt-get update. The /bin/sh -c prefix is how Docker runs the shell form of RUN. Instructions such as COPY may appear as COPY data.tar /tmp/data.tar # buildkit. The # buildkit suffix shows that BuildKit built the layer.
What `<missing>` means
Most rows in the IMAGE column show <missing>. This does not mean the layer is broken or lost.
With BuildKit, intermediate layers do not get their own local image IDs. Layers pulled from a registry also arrive without the IDs of the images that originally contained them. Only the top row, the final image, normally shows a real ID. The base image layers usually show <missing> because you pulled them rather than built them.
So <missing> means "no local image ID is recorded for this layer". The layer's content is still present and still counts toward the size. You cannot run docker run on a <missing> row, but you do not need to. Use the CREATED BY and SIZE columns to understand it.
Quick checklist when reading output
- Start at the bottom row and read upward.
- Note which rows are the base image, and which are yours.
- Find the largest SIZE values first.
- Treat
0Brows as metadata, unless they come from a delete. - Use
--no-truncfor any row you cannot identify. - Ignore
<missing>. It describes IDs, not content.
Common errors
- Treating SIZE as cumulative. Each row is separate. Add them to get the total.
- Trusting
0Bafter a delete. The earlier layer still holds the data. - Assuming
<missing>is corruption. It is normal for pulled and BuildKit layers. - Judging a truncated command. Run with
--no-truncfirst.
Exercise
In docker history output, the row for RUN rm /tmp/data.tar shows 0B, yet the image is still large. Why, and which row actually holds the bytes of data.tar?
Show answer
A layer records changes, and deleting a file only adds a marker that hides it in later layers. The bytes remain in the earlier layer, so the row for COPY data.tar /tmp/data.tar holds them. The rm row shows 0B because the marker is tiny, not because space was freed.
Exercise
A teammate sees <missing> in the IMAGE column for most rows and says the image is damaged. What do you tell them?
Show answer
<missing> only means no local image ID is recorded for that layer. This is normal for layers pulled from a registry and for intermediate BuildKit layers. The layer content is intact and still counts toward the image size.