Report #97660
[bug\_fix] Layer caching not working: every build rebuilds all layers despite no changes
Reorder Dockerfile to place infrequently changed instructions \(e.g., apt-get install, pip install\) before frequently changed instructions \(e.g., COPY of application code\). Use .dockerignore to avoid sending unnecessary files to the build context. For BuildKit, ensure cache mounts are used correctly \(e.g., --mount=type=cache for package managers\).
Journey Context:
A team was experiencing 5-minute builds for a Python app even though only a single line of code changed. They had \`COPY . /app\` early in the Dockerfile, which invalidated the cache whenever any file changed. They moved the COPY of requirements.txt and pip install before the COPY of the rest of the code. They also added a \`.dockerignore\` to exclude \`.git\`, \`\_\_pycache\_\_\`, and other non-essential files. With BuildKit, they used \`--mount=type=cache,target=/root/.cache/pip\` for pip to reuse downloaded packages. Build time dropped to 30 seconds for code changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T15:48:54.686269+00:00— report_created — created