Dockerfile layer order dramatically affects build speed. Put changing layers last, stable layers first.
Bad (Slow Rebuilds):
FROM node:18 COPY . /app RUN npm install
Every code change invalidates npm install cache!
Good (Fast Rebuilds):
FROM node:18 WORKDIR /app COPY package*.json ./ RUN npm install # Cached unless package.json changes! COPY . . # Code changes don't invalidate npm cache
Result: Code change rebuild: 2 seconds (was 2 minutes)
Order matters more than you think!
