Skip to content

About

Which Dockerfile instruction made the image bigger? Per-instruction layer size diff between two builds

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

dfsize — which Dockerfile line made the image bigger?

Compares two builds of an image and prints a Markdown table: per-instruction layer size before/after, sorted by change.

$ dfsize diff myapp:main myapp:pr --max-growth-mb 50
**Image size (uncompressed):** 148.2 MB → 862.9 MB (+714.7 MB)

| Instruction | Before | After | Δ |
|---|---:|---:|---:|
| `RUN pip install torch` | — | 700.0 MB | +700.0 MB |
...
  • dfsize snapshot IMAGE -o main.json stores layer sizes (e.g. as a CI artifact from main); dfsize diff main.json myapp:pr compares against it.
  • --max-growth-mb N exits 1 if the total grows more than N MB (CI gate).
  • Sizes are uncompressed layer sizes from docker history. Compressed (registry) sizes are never mixed in.
  • Layers are matched by normalized instruction text (difflib alignment, oldest first). That is deliberately simple and has limits (below).

Stage-0 findings (what was and was not checked)

Checked locally here: docker history --no-trunc on BuildKit-built images exposes CreatedBy per layer with # buildkit suffix and per-layer size, so text matching works for single-stage builds and for the final stage of multi-stage builds; the tests build real images. Not verified (no web research was done for this repo): current state of container-diff (the brief says archived, last push 2024-03-27), dive, docker scout compare. Treat the "no existing tool does this" claim from the brief as unverified.

Known limits

  • Only the final stage's layers are visible in docker history; COPY --from appears as a COPY layer, not as the producing stage.
  • If the same instruction text occurs twice, alignment is by order; a squashed image (--squash) has no per-instruction layers.
  • If a base image changes, its layers show as removed/added build steps of the base (that is real information, but noisy).

GitHub Action

action.yml builds the Dockerfile at the PR head and at the base ref and posts the table to the job summary. (Note: Actions are currently disabled on the author's account, so the Action is untested in CI; the CLI is tested locally.)

Dev

pip install -e .[dev] && pytest (the real-build test needs a running Docker daemon and alpine:3.20; skipped otherwise).

About

Which Dockerfile instruction made the image bigger? Per-instruction layer size diff between two builds

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages