Report #2232
[bug\_fix] BuildKit layer cache invalidated on every build despite no changes to copied files
Add a trailing slash to the destination directory in the COPY instruction \(e.g., change \`COPY package.json /app\` to \`COPY package.json /app/\`\).
Journey Context:
A developer notices that the \`RUN npm install\` step in their Dockerfile is never cached by BuildKit, causing 5-minute builds on every commit. They verify that \`package.json\` hasn't changed and check the file hashes. They dig into BuildKit's cache mechanics and realize that \`COPY package.json /app\` \(without a trailing slash\) creates a file named \`app\` if the directory doesn't already exist, or modifies the directory inode metadata. This alters the layer's filesystem checksum, invalidating the cache for all subsequent layers. Adding the trailing slash explicitly tells Docker that \`/app/\` is a directory, preserving the directory inode and maintaining the cache key.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T10:19:36.523726+00:00— report_created — created