A transit app rebuilds the entire image when only an HTML asset changed because dependency installs sit after the full source COPY. How should the Dockerfile be ordered?
Select an answer to reveal the explanation.
Short Explanation
Docker's cache is a lazy chef: if an early step changes, everything after gets recooked. Put the stable recipe (package.json and npm install) above the often-edited HTML so a tiny asset tweak only rebuilds the thin top layers.
Full Explanation
Layer caching invalidates an instruction and all following instructions when its inputs change. Copying lockfiles and installing dependencies before copying volatile application files preserves the expensive dependency layer across content edits. Init containers and DaemonSets do not repair Dockerfile ordering for build-time cache efficiency.