Sitemap

Distroless Containers: The Future of Secure & Lightweight Deployments

3 min readFeb 22, 2025

--

In the world of containerization, security, performance, and size are crucial. Traditional container images often include unnecessary system libraries, shells, and package managers, increasing their attack surface. This is where Distroless containers come into play!

Distroless images strip away the non-essential components, leaving only what your application needs to run. In this article, we’ll explore:
What Distroless containers are
Why they are better than traditional images
How to build and deploy a Node.js app using Distroless

What are Distroless Containers?

Distroless containers are minimalist Docker images that do not include a full Linux distribution. Unlike Alpine, Ubuntu, or Debian-based images, Distroless removes:
Shell (bash, sh)
Package managers (apt, yum)
Extra OS utilities

Instead, they only include essential runtime libraries, making them smaller, faster, and more secure.

Google pioneered Distroless images, and they are available under gcr.io/distroless.

Why Use Distroless Containers?

1. Smaller Image Size

Traditional containers bundle unnecessary files, leading to bloated images. Distroless removes everything except runtime dependencies, reducing image size dramatically.

Press enter or click to view image in full size
Difference in size

2. Enhanced Security

Every installed package in a container increases the risk of vulnerabilities. Since Distroless has no shell or package manager, the attack surface is minimal.

Hackers can’t:

Run apt-get install

Open an interactive shell

Modify system files

A smaller attack surface = better security! 🔐

3. Faster Startup & Performance

Fewer files = Less time to load! 🚀
Since the image is smaller, the container starts faster and consumes fewer resources.

4. Reduced Maintenance

Traditional images require regular security updates for system libraries. Distroless eliminates unnecessary OS components, reducing patching efforts.

🛠 How to Build & Deploy a Node.js App with Distroless

Step 1 ⃣: Create a Simple Node.js App

First, set up a basic Express.js server.

const express = require(‘express’);
const app = express();

app.get(‘/’, (req, res) => res.send(‘Hello, Distroless!’));

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));

Step 2 ️⃣: Create a Multi-Stage Dockerfile

Using multi-stage builds, we first install dependencies in a temporary container, then copy only the necessary files into a Distroless image.

# Stage 1: Build dependencies
FROM node:18 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install — only=production
COPY . .

# Stage 2: Create a minimal runtime environment
FROM gcr.io/distroless/nodejs18
WORKDIR /app
COPY — from=builder /app /app
CMD [“index.js”]

Step 3⃣: Build & Run the Distroless Container

Now, let’s build and run our lightweight container.

# Build the image
docker build -t my-node-app:distroless .

# Run the container
docker run -p 3000:3000 my-node-app:distroless

Your app is now running on a Distroless container!

Deploying to Kubernetes

Distroless containers are perfect for Kubernetes deployments. Here’s how you can deploy it:

Get Sam Atmaramani’s stories in your inbox

Join Medium for free to get updates from this writer.

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: distroless-app
spec:
replicas: 2
selector:
matchLabels:
app: distroless-app
template:
metadata:
labels:
app: distroless-app
spec:
containers:
— name: distroless-app
image: my-dockerhub-username/my-node-app:distroless
ports:
— containerPort: 3000

Apply the deployment:

kubectl apply -f deployment.yaml

Debugging a Distroless Container

One limitation of Distroless containers is debugging. Since there’s no shell (sh, bash), traditional debugging tools won’t work.

To debug, use:

docker run -it — entrypoint sh gcr.io/distroless/nodejs18

Alternatively, use busybox:

kubectl debug -it distroless-app — image=busybox

🔹 Distroless vs Alpine vs Ubuntu

Press enter or click to view image in full size

When to Use Distroless Containers?

Microservices & API Deployments
Kubernetes Deployments
Serverless Applications (AWS Lambda, GCP Cloud Run, etc.)
Security-Critical Environments

Avoid if you need:
A shell for debugging
A package manager (apt, yum)
Legacy software compatibility

2 Cents from Author “Sam”

Distroless containers offer maximum security, reduced attack surfaces, and smaller image sizes — making them an ideal choice for production deployments. If you’re running Node.js, Python, Java, or Go applications, switching to Distroless is a no-brainer.

Feel free to follow me at below social handles

My LinkedIn Profile https://www.linkedin.com/in/sampurna/

My youTube Channel https://www.youtube.com/@techysam-bl9mk/videos

My Udemy Tutorial link https://www.udemy.com/courses/search/?src=ukw&q=sampurna+atmaramani

My Github Link https://github.com/satmaramani

--

--

Sam Atmaramani
Sam Atmaramani

Written by Sam Atmaramani

Javascript FullStack + Udemy Instructor + Seasoned YouTuber + Web & Mobile App Devloper http://sam-portfolio-site.s3-website.ap-south-1.amazonaws.com/