interview-prep

Each Dockerfile instruction creates a layer. Layers are cached and reused. Order instructions from least-changing to most-changing to maximise cache hits.

Bad:

COPY . .                    # invalidates cache on any code change
RUN pip install -r requirements.txt

Good:

COPY requirements.txt .     # only changes when requirements change
RUN pip install -r requirements.txt
COPY . .                    # code changes don't invalidate the install layer

My notes