How do you make an image reproducible so the same commit gives the same bytes?
AdvancedScenarioImage design and Dockerfile decisions
Answer
Situation read → Timestamps, unpinned packages and unordered layers cause drift.
What I'd do →
- Pin base by digest and OS packages by version or use a snapshot mirror (e.g. snapshot.debian.org).
- Use lockfiles (
npm ci,pip --require-hashes,go.sum). - Build with
SOURCE_DATE_EPOCHand--output type=image,rewrite-timestamp=trueon BuildKit. - Use
-trimpathand deterministic compilers settings.
Why → Reproducibility allows independent verification of provenance and attestations.
Interview tip → Be honest that full bit-for-bit reproducibility is hard; aim for it on the supply-chain-critical images.
More on Image design and Dockerfile decisions
A teammate's Node.js image is 1.2 GB. How do you approach shrinking it?BeginnerYou need to run `apt-get install` in a Dockerfile. How do you write it so the layer stays small and cache-safe?BeginnerWhen would you pick `COPY` over `ADD`?BeginnerA service must run a startup script and then the app. Should you use `CMD`, `ENTRYPOINT`, or both?BeginnerYour Docker build re-installs all Python dependencies on every code change. Fix it.BeginnerProduct asks for a container that runs both nginx and a Python app. What do you say?Beginner