Q&A
Q&AWhy can COPY . invalidate dependency layers in a Docker build?
Every later layer is invalidated when an earlier instruction input changes.
Read the concise answer
If the whole source tree is copied before dependency installation, any source edit changes that COPY layer and invalidates all subsequent build steps. Copy lockfiles first, install from them, then copy source. Confirm the result with build output and a clean build; cache reuse should improve speed, not alter correctness.