Signal9Signal9 — home
online
back to labs

Image Builds: Stop Busting the Layer Cache

MediumDevOps10-15 min
The brief

The Dockerfile at /root/case/Dockerfile rebuilds slowly: it copies the whole app (COPY . .) BEFORE installing dependencies, so any source edit changes that early layer and busts the cache for the pip install below it — every build re-runs the install. Reorder the Dockerfile to the cache-friendly pattern: copy only the dependency manifest (requirements.txt) and run the install FIRST, then copy the rest of the source. Grading reads the Dockerfile, so fix the file in place.

What you'll do
  • Copy the dependency manifest and install before copying the whole source tree
  • Move the full-context COPY to after the dependency install
  • Keep the build otherwise working

Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.