Madhu Akula

A practical guide to writing secure Dockerfiles

Your Dockerfile is a critical form of infrastructure as code. Learn to write secure, minimal images and automate security checks before deployment.

A practical guide to writing secure Dockerfiles
#1about 2 minutes

Why Dockerfile security is a critical foundation

Dockerfiles act as the blueprint for container images, making their security essential for preventing supply chain attacks and infrastructure compromise.

#2about 5 minutes

Following official Docker best practices for images

Start with small base images, use multi-stage builds, and manage the build context with a .dockerignore file to create efficient and secure containers.

#3about 4 minutes

Advanced security practices for hardening Dockerfiles

Enhance security by running containers as a non-root user, using COPY instead of ADD, avoiding hardcoded secrets, and pulling from trusted image registries.

#4about 4 minutes

Using Docker BuildKit to handle secrets securely

Docker's BuildKit allows mounting secrets and forwarding SSH agents during the build process, preventing sensitive credentials from being stored in image layers.

#5about 5 minutes

Automating checks with linters like Hadolint and Dockle

Use automated linters like Hadolint for best practices and Dockle for CIS benchmark compliance to enforce security standards in your CI/CD pipeline.

#6about 2 minutes

Reducing attack surface with Docker-slim

Docker-slim minifies container images by removing unnecessary files and can automatically generate seccomp and AppArmor profiles to harden runtime security.

#7about 3 minutes

Analyzing image layers for security with Dive

The Dive tool provides a layer-by-layer inspection of a Docker image, helping to identify inefficiencies and potential security risks like backdoors.

#8about 4 minutes

Introducing Open Policy Agent for custom policies

Open Policy Agent (OPA) and its language Rego provide a general-purpose engine for enforcing custom, organization-specific security policies on structured data like Dockerfiles.

#9about 6 minutes

Writing custom Dockerfile policies with Conftest

Leverage Conftest to write and apply custom Rego policies that validate Dockerfiles against specific organizational rules, such as only allowing images from a trusted private registry.

#10about 2 minutes

Next steps for implementing Dockerfile security

Implement security best practices early using linters in your IDE, integrate automated checks into CI/CD pipelines, and create standardized custom policies for your organization.

Related jobs
Jobs that call for the skills explored in this talk.

Featured Partners

Related Articles

View all articles
AG
Andre Braun, GitLab
Now is the time for industrialized software development
Now is the time for industrialized software development Recently, I received a letter from my car’s manufacturer alerting me to a recall. They had discovered a defective part and wanted to replace it. It was easily fixed, and I might have forgotten a...
Now is the time for industrialized software development
DC
Daniel Cranney
Dev Digest 194: AI vs. Version Control, Password Louvre & Cursed Webdev
Inside last week’s Dev Digest 194 . 🧠 Learn how to become an AI-native software engineer 🤷‍♂️ How can you stand out when anyone can build anything? 👂 Whisper Leak allows listening to encrypted chats 🐝 What’s new the OWASP2025 Top Ten List 🙅‍♀️ Curse...
Dev Digest 194: AI vs. Version Control, Password Louvre & Cursed Webdev
CH
Chris Heilmann
Dev Digest 138 - Are you secure about this?
Hello there! This is the 2nd "out of the can" edition of 3 as I am on vacation in Greece eating lovely things on the beach. So, fewer news, but lots of great resources. Many around the topic of security. Enjoy! News and ArticlesGoogle Pixel phones t...
Dev Digest 138 - Are you secure about this?
DC
Daniel Cranney
Building AI Solutions with Rust and Docker
In recent years, artificial intelligence has surged in popularity in the world of development. While Python remains a popular choice in the realm of AI, Rust - often known as Rust Lang - is quickly emerging as a formidable alternative.Rust programmin...
Building AI Solutions with Rust and Docker

From learning to earning

Jobs that call for the skills explored in this talk.

DevOps

DevOps

UnderDefense

Remote
Bash
Azure
React
Kafka
+16
DevSecOps Engineer

DevSecOps Engineer

Accenture
Municipality of Bilbao, Spain

API
Scrum
DevOps
Docker
Kubernetes
+1
DevSecOps Engineer

DevSecOps Engineer

Accenture
Municipality of Madrid, Spain

API
Scrum
DevOps
Docker
Kubernetes
+1