🐳Docker Static Security Testing Labs

🎯 Objective

Learn to perform static analysis on Dockerfiles to identify security issues before building images.


🧰 Prerequisites

  • Dockerfile available for testing

  • Tools: hadolint, dockle, checkov

  • A system with Docker and internet access


πŸ”Ή Lab 1: Create a Sample Insecure Dockerfile

# Dockerfile
FROM ubuntu:latest

RUN apt update && apt install -y curl sudo

ADD secret.txt /root/secret.txt

RUN chmod 777 /root/secret.txt

CMD ["bash"]

Save it as Dockerfile.


πŸ”Ή Lab 2: Check with hadolint (Dockerfile Linter)

Step 1: Install hadolint

Just install using brew:

or download the binary:

Step 2: Check using hadolint

βœ… Detects issues like use of latest, insecure permissions, and ADD instead of COPY.


πŸ”Ή Lab 3: Check Image with dockle

Dockle checks container image best practices and Dockerfile structure.

Step 1: Install dockle

Step 2: Check with dockle

Build the container image using the Dockerfile from previous lab:

Now check the container image using dockle:

βœ… Report will include missing HEALTHCHECK, USER, writable files, etc.


πŸ”Ή Lab 4: Scan Dockerfile with checkov

Checkov is a static code analysis tool for infrastructure security including Dockerfiles.

Step 1: Install Checkov

Using brew:

Or directly with pip:

Step 2: Run Checkov against a Dockerfile

βœ… Identifies misconfigurations based on best practices and compliance checks.


πŸ”Ή Lab 5: Use GitHub Actions for CI Security Testing (Optional)

βœ… Adds multi-tool static testing to your pipeline.


βœ… Wrap-Up

  • βœ… Used hadolint, dockle, and checkov for Dockerfile scanning

  • βœ… Detected vulnerabilities and bad practices

  • βœ… Integrated multiple tools into a CI pipeline


Last updated