Updated November 2026: Updated for Docker 29: docker history with --no-trunc and --format, compressed layer sizes from the registry, dive, and how to shrink the big layers you find.

When an image is bigger than expected, I want to know which layer is to blame. Docker answers that question with one command, and a few more help you dig deeper. All commands and numbers in this post come from Docker 29.

What are Docker image layers

Every instruction in a Dockerfile that changes the filesystem (FROM, RUN, COPY, ADD) produces a layer. Instructions like CMD, ENV or LABEL only change metadata and show up as 0 B entries. The layers are stacked on top of each other, and together they form the image.

Layers are immutable. If a later instruction deletes a file, the bytes still sit in the layer that created it; the new layer only records that the file is gone. That is why layer sizes matter.

Every instruction adds a layer, and deleting files later does not shrink the ones below

The size of the entire image

docker image ls shows the size of each image:

BASH
docker pull ubuntu:24.04
docker image ls ubuntu:24.04
PLAIN
IMAGE          ID             DISK USAGE   CONTENT SIZE   EXTRA
ubuntu:24.04   9c7f200c07e3        141MB         30.9MB

With the containerd image store (the default for new installs since Docker Engine 29 and in Docker Desktop), you get two numbers. CONTENT SIZE is the compressed size, which is roughly what gets pushed and pulled. DISK USAGE is what the image takes up locally, unpacked layers plus the compressed blobs. Older setups with the classic storage driver show a single SIZE column.

That tells you that an image is big, not why.

The size of each layer with docker history

docker history lists all layers of an image, newest first, together with the instruction that created each one and its size:

BASH
docker history ubuntu:24.04
PLAIN
IMAGE          CREATED      CREATED BY                                      SIZE      COMMENT
9c7f200c07e3   9 days ago   /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B
<missing>      9 days ago   /bin/sh -c #(nop) ADD file:2a6d7d3511af5b48d…   110MB
<missing>      9 days ago   /bin/sh -c #(nop)  LABEL org.opencontainers.…   0B
<missing>      9 days ago   /bin/sh -c #(nop)  ARG LAUNCHPAD_BUILD_ARCH     0B
<missing>      9 days ago   /bin/sh -c #(nop)  ARG RELEASE                  0B

<missing> is nothing to worry about. Layers of pulled images do not have a local image ID; only the top entry does. The SIZE column is the uncompressed size of the layer.

The CREATED BY column gets cut off. Add --no-trunc to see the full instruction:

BASH
docker history --no-trunc ubuntu:24.04

--no-trunc also prints full sha256 IDs and makes the table very wide. I usually combine it with --format and only keep the columns I care about:

BASH
docker history --no-trunc --format '{{.Size}}\t{{.CreatedBy}}' ubuntu:24.04
PLAIN
0B	/bin/sh -c #(nop)  CMD ["/bin/bash"]
110MB	/bin/sh -c #(nop) ADD file:2a6d7d3511af5b48de2ccdad66ef2aa7544bf264ce928935ad4469c76a66169b in /
0B	/bin/sh -c #(nop)  LABEL org.opencontainers.image.version=24.04
...

Two more flags are handy for scripts: --human=false prints sizes in bytes, and --format json prints one JSON object per layer.

Find the layer that makes your image big

Here is a Dockerfile that looks harmless:

DOCKERFILE
FROM ubuntu:24.04
RUN apt-get update
RUN apt-get install -y curl
RUN rm -rf /var/lib/apt/lists/*

docker history shows where the space goes:

BASH
docker build -t layers-demo:bad .
docker history layers-demo:bad
PLAIN
IMAGE          CREATED          CREATED BY                                      SIZE      COMMENT
af8e7e512795   11 seconds ago   RUN /bin/sh -c rm -rf /var/lib/apt/lists/* #…   20.5kB    buildkit.dockerfile.v0
<missing>      11 seconds ago   RUN /bin/sh -c apt-get install -y curl # bui…   11.4MB    buildkit.dockerfile.v0
<missing>      20 seconds ago   RUN /bin/sh -c apt-get update # buildkit        59.4MB    buildkit.dockerfile.v0
<missing>      9 days ago       /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B
<missing>      9 days ago       /bin/sh -c #(nop) ADD file:2a6d7d3511af5b48d…   110MB
...

The package lists from apt-get update take 59.4 MB, and the rm in the last step does not get them back. It only adds a 20.5 kB layer that hides them.

docker image inspect

docker image inspect does not print per-layer sizes, but it tells you how many layers an image has and its total size in bytes:

BASH
docker image inspect -f '{{len .RootFS.Layers}} layers, {{.Size}} bytes' layers-demo:bad
PLAIN
4 layers, 255394276 bytes

Only FROM, RUN, COPY and ADD count here; metadata-only instructions do not create a layer. {{json .RootFS.Layers}} prints the layer digests themselves.

Compressed layer sizes in a registry

docker history shows uncompressed sizes. If you care about pull time, you want the compressed size of each layer, and that lives in the image manifest in the registry. docker buildx imagetools inspect reads it without pulling the image. For a multi-platform image, first pick the manifest for your platform, then list its layers:

BASH
digest=$(docker buildx imagetools inspect --raw ubuntu:24.04 \
  | jq -r '.manifests[] | select(.platform.os=="linux" and .platform.architecture=="amd64") | .digest')

docker buildx imagetools inspect --raw "ubuntu:24.04@$digest" | jq '.layers[] | {size, digest}'
JSON
{
  "size": 29793297,
  "digest": "sha256:8e8df94085bf9af8de500d2042195f1819a4c381b7f3be2a6b920cab65039050"
}

The 110 MB base layer is 29.8 MB on the wire.

Look inside layers with dive

docker history tells you which layer is big. dive tells you what is in it. It shows each layer’s file tree, highlights added, changed and removed files, and estimates how much space is wasted on files that are overwritten or deleted in later layers. dive is actively maintained; v0.13.1 is the current release.

BASH
# macOS
brew install dive

# or without installing anything
docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock wagoodman/dive layers-demo:bad
BASH
dive layers-demo:bad

Set CI=true and dive skips the UI and fails with a non-zero exit code when the image breaks the rules from a .dive-ci file, such as lowestEfficiency or highestWastedBytes. That is a cheap way to keep image size from creeping up in a pipeline:

BASH
CI=true dive layers-demo:bad

Shrink the big layers

Once you know which layer is big, these three fixes cover most cases.

Clean up in the same RUN step. Files you delete in the same instruction never end up in a layer. Adding --no-install-recommends skips optional packages too:

DOCKERFILE
FROM ubuntu:24.04
RUN apt-get update \
 && apt-get install -y --no-install-recommends curl \
 && rm -rf /var/lib/apt/lists/*

The new layer is 6.89 MB instead of 70.8 MB, and docker image ls shows 31.5 MB content size instead of 74.1 MB.

Use a multi-stage build. Compilers, SDKs and build caches stay in the build stage. Only the artifact is copied into a small runtime image:

DOCKERFILE
FROM golang:1.26 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /out/app .

FROM gcr.io/distroless/static-debian13
COPY --from=build /out/app /app
ENTRYPOINT ["/app"]

For a hello-world Go app the final image is 10.3 MB on disk and the only layer I added is the 2.33 MB binary.

Add a .dockerignore. COPY . . copies everything in the build context into a layer: .git, node_modules, local build output, logs. Exclude what the image does not need:

PLAIN
.git
node_modules
target
*.log

Then run docker history again and check that the big layer is gone.