# Guided Exercise: Order These Instructions for Maximum Cache Efficiency This is a paper exercise — commit to an order before checking it in the Lab. ## Your task You need a Dockerfile with these five things, in SOME order. Application code changes very often; dependencies change rarely. Write the most cache-efficient order: - `FROM python:3.11-slim` - `COPY app.py .` (your actual application code — changes often) - `COPY requirements.txt .` (dependency list — changes rarely) - `RUN pip install -r requirements.txt` (installs dependencies — slow) - `WORKDIR /app` ## A worked shape to check yourself against ``` FROM python:3.11-slim WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY app.py . ``` Copying `requirements.txt` and installing dependencies BEFORE copying the actual application code means a code-only change never invalidates the (slow) dependency-install layer — only the final `COPY app.py .` step needs to rerun. ## Instructor Notes **Facilitation:** This is one of the most practically useful habits in the entire module — worth connecting explicitly to real build-time savings on larger, slower dependency installs. **Approximate timing:** 8-10 minutes live discussion; 5 minutes self-paced.