dev.to Docker guidance: multi-stage builds and minimal base images to shrink containers
Article Content
- •Multi-stage builds keep compilers and SDKs out of the final production image.
- •Minimal base images such as Alpine, distroless and scratch reduce packages an attacker can use.
- •Alpine's musl libc may cause glibc-built binaries to fail; distroless and scratch lack a shell for debugging.
- •Debugging tools should be injected via ephemeral debug containers rather than baked into production images.
- •Fewer packages mean fewer CVE flags from scanners such as Trivy and Grype.
Tanmay Kumar Chaurasia published a DEV Community post on 2026-11-21 on building smaller, safer Docker containers. The post argues that default base images include compilers, shells and package managers that bloat production images and widen the attack surface. It recommends multi-stage builds, which keep SDKs and source code in a build stage and copy only compiled artifacts into a clean runtime stage. It recommends minimal base images such as Alpine, Google's distroless images and scratch, noting trade-offs: Alpine's musl libc may break glibc-built binaries, and distroless and scratch images lack a shell for live debugging. For Node.js it recommends a two-stage build that installs production dependencies in the runtime stage. It advises against baking debugging tools such as gdb and curl into production images and suggests ephemeral debug containers in Kubernetes instead. It also recommends stateless, immutable images that stream logs to stdout and stderr. The articles state that smaller images reduce scanner CVE flags from tools such as Trivy and Grype and limit post-exploitation options for an attacker. This is general best-practice guidance and does not describe a specific vulnerability or incident.
Ask AI about this cluster
Answers cite the sources they use
Timeline
More articles in this cluster (2)
Common questions
Does this affect my existing containers?
Will switching to Alpine break my application?
How do I debug a container without a shell?
Continue Reading
Critical Apache Roller RCE Vulnerability Actively Exploited in the Wild Apache has issued a warning regarding a critical remote code execution (RCE) vulnerability in Apache Roller, tracked as CVE-2026-129448, which is actively being exploited. This flaw affects versions 4.0.0 through 6.1.4 and allows unauthenticated attackers to execute arbitrary code via the XML-RPC endpoint. The…