Sachin Chaurasiya

Package · Container build & runtime

Docker

Docker provides the Dockerfile build format, BuildKit and a runtime for OCI containers. It is the packaging step whose choices — base image, user, layers — decide most of the vulnerability surface.

Stage
Package
Category
Container build & runtime
Documentation
Official docs
License
Apache-2.0 (Moby)
On this page

What it does

Builds images from Dockerfiles with BuildKit (multi-stage builds, cache mounts, secrets mounts) and runs containers locally.

Where it fits

Package stage. Security decisions made here — minimal base images, non-root users, pinned digests, no secrets in layers — determine how much the Secure stage will find.

Quick start

docker build --pull -t app:dev .
docker run --rm --read-only --cap-drop ALL --user 10001 app:dev
docker buildx build --sbom=true --provenance=true -t registry.example.com/app:1.2.3 --push .

Common pitfalls

  • Mounting /var/run/docker.sock into CI agents grants root on the host; prefer Kaniko or rootless BuildKit.
  • --build-arg values are recorded in image history; use --mount=type=secret for build-time credentials.
  • Mutable tags (latest) make scans unreproducible; deploy by digest.

Hands-on labs using Docker

Lab

Secure Docker Images with Trivy

Build a deliberately weak image, scan it with Trivy, and rebuild it until the gate for fixable HIGH and CRITICAL findings passes: current base, non-root user, patched packages, no pip in the runtime image.

beginner 30 minutes Trivy · Docker
Lab

Generate an SBOM with Syft and Scan It with Grype

Produce CycloneDX and SPDX bills of materials for a container image without a Docker socket, scan the SBOM with Grype, gate on fixable findings only, and see why the SBOM is worth keeping after the release.

intermediate 35 minutes Syft · Grype · Docker

Articles about Docker

Security Tools beginner

Container Image Scanning with Trivy

How Trivy finds OS and application vulnerabilities, secrets and misconfigurations in container images, how to make the results actionable, and how to wire it into CI without slowing builds down.

9 min read
CI/CD intermediate

Building a Secure CI/CD Pipeline with Jenkins

A declarative Jenkins pipeline with secrets scanning, SAST, image scanning and least-privilege credential handling — and the agent, plugin and Docker decisions that keep it that way.

9 min read