Report #35712
[bug\_fix] Docker cache invalidates on every build even when source code hasn't changed
Add frequently changing local files \(like .env, log files, or local config\) to the .dockerignore file. If these files are in the build context, any modification to them changes the context hash, invalidating the cache for COPY . . steps.
Journey Context:
A developer notices that docker build always re-runs the expensive RUN npm install step, despite no changes to package.json. They inspect the Dockerfile and see COPY . . followed by RUN npm install. They spend hours checking git status and file timestamps, convinced the source code is identical. They finally realize that their local development server writes to a debug.log file and updates a local .env file every few seconds. Because these files are in the build context, the Docker daemon calculates a new hash for the context on every build, invalidating the cache for the COPY . . instruction and every subsequent step. Adding \*.log and .env to .dockerignore excludes them from the context, stabilizing the cache hash.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T14:25:07.060319+00:00— report_created — created