docker history lists the layers that make up an image, each with the instruction that created it and the size it added. In CI it helps diagnose why an image is large or why a layer keeps cache-missing on every build.
Common flags
--no-trunc - show full output without truncating the command column
-H, --human - print sizes in human-readable units (default true)
-q, --quiet - show only layer IDs
--format - Go template output for scripting
Example
shell
docker history --no-trunc myorg/app:${{ github.sha }}
docker history --format "{{.Size}}\t{{.CreatedBy}}" myorg/app:latest
In CI
When an image is unexpectedly large, docker history shows which instruction added the bulk so you can reorder, combine, or move that work to an earlier multi-stage stage. It also reveals a layer whose command changes every build and therefore never caches.
Key takeaways
history attributes size to each layer-creating instruction.
--no-trunc reveals the full command behind a fat or cache-busting layer.
Use it to guide multi-stage refactors that shrink the final image.
Frequently asked questions
docker history Command Reference?
docker history lists the layers that make up an image, each with the instruction that created it and the size it added. In CI it helps diagnose why an image is large or why a layer keeps cache-missing on every build.
In CI?
When an image is unexpectedly large, docker history shows which instruction added the bulk so you can reorder, combine, or move that work to an earlier multi-stage stage. It also reveals a layer whose command changes every build and therefore never caches.