Pick the fix
Every code change makes the image build reinstall all dependencies. Fix?
Hint 1 of 1
Which layer changes on every commit?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Copy the lock file and install dependencies before copying the source
Correct. The dependency layer stays cached.
Docker reuses a cached layer until one of its inputs changes. If the lock file and dependency install come before COPY of the source, code edits only rebuild the layers after them.
Why not the others?
- B Use a bigger build machine. Still reinstalls.
- C Remove the lock file. Makes builds unreproducible.
- D Install dependencies at container start. Slow starts and unpinned results.