Using Docker Hardened Images (DHI)

Using Docker Hardened Images (DHI)

- 2 mins

Introduction

Docker Hardened Images (DHI) provide a minimal, secure, and production-ready base for your containers.
With Docker making DHI free and open source, developers can now use enterprise-grade security without changing their Docker workflow.

What Are Docker Hardened Images (DHI)?

Docker Hardened Images are security-focused base container images built to minimize risk before your application code even runs.

They are:

Think of DHI as “clean-room” base images that remove unnecessary software—the biggest source of container vulnerabilities.

What You Get with Free DHI

The free tier is more than enough for most teams.

Included

This article focuses on Debian 12 hardened base images (dhi.io/debian-base:12), showing how to migrate existing Dockerfiles and create secure applications.


Why Use dhi.io/debian-base:12?

Standard Debian images often include:

By contrast, dhi.io/debian-base:12 offers:

Using DHI reduces attack surface, improves build speed, and strengthens your supply chain.


Part 1: Migrating a Standard Debian Dockerfile

Before (Standard Debian 12 Image)

FROM debian:12

RUN apt-get update && \
    apt-get install -y curl ca-certificates && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY . .
CMD ["bash"]

Problems:

After (Docker Hardened Image)

FROM dhi.io/debian-base:12

RUN apt-get update && \
    apt-get install -y curl ca-certificates && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY . .
CMD ["bash"]

No other changes are required. The image is a drop-in replacement.


Part 2: Python Application Example

FROM dhi.io/debian-base:12

ENV PYTHONUNBUFFERED=1

RUN apt-get update && \
    apt-get install -y python3 python3-pip && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

COPY . .
CMD ["python3", "app.py"]

This setup keeps full Debian compatibility while minimizing vulnerabilities in the base image.


Part 3: Multi-Stage Build Example

Build Stage

FROM dhi.io/debian-base:12 AS builder

RUN apt-get update && \
    apt-get install -y build-essential && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /src
COPY . .
RUN make build

Runtime Stage

FROM dhi.io/debian-base:12

WORKDIR /app
COPY --from=builder /src/bin/app /app/app

CMD ["./app"]

This ensures both build and runtime images are hardened and traceable.


Conclusion

Security starts with the base your application runs on.
By switching to dhi.io/debian-base:12, you immediately:

Docker Hardened Images make secure-by-default containers accessible to everyone, and Debian 12 DHI is the safest way to run Debian in production today.


Thanks for reading!

Guneycan Sanli

Guneycan Sanli

Guneycan Sanli

A person who like learning, music, travelling and sports.

comments powered by Disqus