Report #94321
[bug\_fix] COPY . /app invalidates cache on every single commit
Add \`.git\` and other VCS metadata directories to \`.dockerignore\`. The root cause is that \`COPY . .\` calculates the checksum of all files in the context. If \`.git\` is included, every commit changes the \`.git\` objects, altering the context checksum and invalidating the cache for that \`COPY\` layer and all subsequent layers.
Journey Context:
A developer notices CI builds take 10 minutes every time, even for a 1-line README change. They check the build logs and see \`CACHED\` for \`RUN apt-get install\`, but \`COPY . /app\` never caches. They suspect Docker is broken or the CI is wiping the cache. They add verbose logging and realize the cache key for the \`COPY\` step changes on every run. They list the build context files and see the massive \`.git\` directory is being sent to the daemon. Because every Git commit modifies files inside \`.git\`, the checksum of the context changes, breaking the cache. Adding \`.git\` to \`.dockerignore\` stabilizes the context checksum, restoring the cache.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:54:17.901114+00:00— report_created — created