Tanmay Kumar Chaurasia published a DEV Community post on Nov. 21, 2026, on multi-stage builds, minimal base images and stateless containers to cut image size and attack surface.
Tanmay Kumar Chaurasia, a backend and DevOps engineer, published a DEV Community post on Nov. 21, 2026, on building smaller and safer Docker containers. The post argues that default base images carry build tools and package managers that bloat production images and widen the attack surface.
Default base images often ship with compilers and shells. Those tools help during development, yet they bloat production images and widen the attack surface. Every extra package becomes another item to scan, patch and maintain. If an attacker gains execution inside a container, tools like apt and curl ease post-exploitation.
Multi-stage builds separate compilation from execution. The build stage holds SDKs and source code. The runtime stage copies compiled artifacts into a clean image. In a Go service, the final image contains the binary, not the Go toolchain.
This removes the Go compiler and source files from the final image.
Minimal base images reduce the footprint. Alpine Linux weighs 5 MB and uses musl libc with busybox. Distroless images, which Google maintains, contain the application and its runtime dependencies, such as Python or Node.js, without package managers or shells. Scratch provides an empty base for statically compiled binaries such as Go or Rust applications.
Each option carries trade-offs. Alpine uses musl libc, so binaries built against glibc may fail. Distroless removes the shell, which complicates live debugging; teams can use ephemeral debug containers or distroless debug variants. Scratch requires a static binary and offers no shell for inspection.
For Node.js, Chaurasia recommends a two-stage build that installs dependencies, builds the application, then installs production dependencies in the runtime stage.
Do not bake debugging tools into production images. Tools such as gdb and curl belong in active debugging sessions, injected through ephemeral debug containers in Kubernetes. Fewer installed binaries leave fewer options for an attacker during a supply chain compromise or command injection exploit.
Images should remain stateless and immutable. Mount host directories or network volumes for persistent storage. Stream application logs to standard output and standard error so orchestrators can capture them. Stateless images allow containers to move across hosts without data loss.
The payoff shows up in operations. Smaller images pull and push in seconds, which keeps CI/CD pipelines responsive. Fewer packages reduce CVE flags from scanners such as Trivy or Grype, which saves triage time. Removing shells and package managers limits what an attacker can do after gaining execution.
Chaurasia works as a backend and DevOps engineer and builds AI agents and automation for businesses. He takes freelance projects and consulting work.
Source : Docker Best Practices: How to Build Smaller and Safer Containers , by tanmay kuamr chaurasia , DEV Community , Nov 21, 2026
The full story
This article is one source in a clustered incident — the cluster page carries the summary, timeline and every other outlet covering it.
