Report #16173
[bug\_fix] Layer cache invalidated on every build despite no code changes \(specifically on COPY . .\)
Add the \`.git\` directory \(and other frequently changing metadata directories like \`.env\` or \`node\_modules\`\) to the \`.dockerignore\` file to prevent them from altering the build context checksum.
Journey Context:
A developer notices their CI builds take 5 minutes every time, even when no source code has changed. They inspect the build logs and see the \`COPY . .\` step never uses the cache. They verify file contents haven't changed and timestamps seem okay. They eventually realize that because they didn't exclude \`.git\`, the entire git history and object database is included in the build context. Since git metadata changes on every branch switch or commit, the checksum of the build context changes, invalidating the cache for \`COPY . .\` and all subsequent layers. Adding \`.git\` to \`.dockerignore\` works because it excludes the volatile metadata from the context tarball, stabilizing the checksum and allowing the layer cache to be reused.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:57:29.903713+00:00— report_created — created