Report #49651
[bug\_fix] Docker build cache invalidated unexpectedly on COPY . /app even when source code hasn't changed.
Add the .git directory to the .dockerignore file to prevent repository metadata changes from altering the build context checksum.
Journey Context:
A developer notices their CI builds take 5 minutes every time, even on simple documentation changes. The COPY . /app step never shows CACHED. They dig into Docker layer caching, assuming it's a Docker bug. They check file contents—they are identical. The rabbit hole deepens when they discover that CI does a fresh git fetch and git checkout right before docker build. This updates file modification timestamps \(mtimes\) in the .git directory. Docker's COPY instruction calculates the cache key using file metadata, including mtimes, not just file contents. Because the .git folder is included in the build context, its constantly changing mtimes cause the COPY . /app cache key to change, invalidating all subsequent layers \(like RUN npm install\). Adding .git to .dockerignore removes the volatile metadata from the context, restoring cache hits.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:49:21.066710+00:00— report_created — created