Course contentsShow
← Cloud and Infrastructure
Lesson 987 of 2,98919. Container FundamentalsFree lesson

Scratch and Distroless Images

Exploring minimal base images: empty 'scratch' and stripped-down distroless for smaller footprints.

Scratch and Distroless Images

What you'll learn: How to create ultra-minimal container images that strip away everything unnecessary for maximum security and efficiency.


By now you understand that container images are built from layers, and those layers add up. But what if you could start with almost nothing?

The scratch Image

scratch is a special, completely empty base image—literally zero bytes. It's Docker's way of saying "start from nothing." When you build FROM scratch, your image contains only what you explicitly add. This is perfect for statically-compiled binaries (like Go programs) that don't need an operating system, shell, or package manager.

Think of it like this: If a normal base image is a furnished apartment, scratch is an empty concrete room. You bring your own everything.

Distroless Images

Google's distroless images sit between traditional base images (like Ubuntu or Alpine) and scratch. They include only the absolute runtime dependencies your application needs—no shell, no package manager, no debugging tools. You get just enough to run Java, Python, or Node.js code, but nothing more.

The analogy: A distroless image is a hotel room with just a bed and bathroom—functional, but no TV, minibar, or room service phone.

Why Bother?

  • Smaller attack surface: No shell means attackers can't easily execute commands
  • Reduced image size: Faster pulls, lower storage costs
  • Compliance and auditing: Fewer components = fewer CVEs to track

Both approaches embrace the "immutable infrastructure" pattern you learned earlier—your container does one thing and nothing else.

Key Takeaway:
scratch offers a truly empty starting point for self-contained binaries, while distroless images provide minimal runtime dependencies—both drastically reduce image size and security risk.