DevOps · interactive
Writing Dockerfiles that cache well
Each instruction is a cached layer. When a layer's inputs change, it and every layer after it rebuild. Copying all your code before installing dependencies means a one-line code change reinstalls everything.
- FROM node:22-slimCACHED
- WORKDIR /appCACHED
- COPY . .1s
- RUN npm ci45s
- RUN npm run build20s
- CMD ["node", "dist/server.js"]0s
rebuild: 66 s
COPY . . changed, so npm ci reruns: 45 s of reinstalling dependencies you didn't touch.
Dockerfile
You changed
Step 1 of 4 · read left to right
In production
Tools and technologies
Build caching is the biggest lever on Docker build time.
Not tied to one language — use these names when you search docs or design a system.