Minimizing Image Size with Slim and Distroless Bases
Shrink final images by choosing minimal base images, removing build tooling, and using distroless or scratch bases for faster pulls and a smaller attack surface.
Why Image Size Matters
Smaller images pull faster, start quicker, cost less to store, and expose fewer packages to attackers. Optimizing size is both a performance and a security win.
Choosing a Lean Base
Default images are convenient but heavy. Swapping node:20 (~1GB) for node:20-slim or node:20-alpine can cut hundreds of megabytes instantly.
FROM node:20-slimAll lessons in this course
- Multi-Stage Builds for Efficiency
- Leveraging Build Caching
- Dockerfile Security Best Practices
- Minimizing Image Size with Slim and Distroless Bases