Cutting Docker build times with layer ordering
The single highest-leverage Dockerfile habit: install dependencies before copying source. Dependencies change rarely, so that layer stays cached across every content edit.
COPY requirements.txt .
RUN pip install -r requirements.txt # cached until requirements change
COPY . . # only this re-runs on a content edit
Get the order wrong and every one-character change reinstalls the world.