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.
Path 01 · learning path
Building a delivery pipeline with security gates that developers can live with: secrets detection, SAST, image scanning and controlled deployment, in Jenkins and GitLab CI.
Each part names what it needs. Nothing has to be installed before part 1.
The path
Each part states what it assumes from the previous one, so you can also jump in where your setup already is.
Stop credentials from reaching Git: run Gitleaks in pre-commit hooks and CI, tune rules and allowlists, handle findings without leaking them further, and decide when history rewriting is worth it.
The GitLab pipeline that gated this site while it ran CI: frozen installs, parallel quality gates, Trivy with SAST and secret detection, artifact verification, and one deployment owner behind protected main.
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.
Practise
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.
Seed a repository with realistic fake secrets, catch them with Gitleaks in history and working-tree modes, ignore a confirmed false positive by fingerprint, and block the next one at commit time.
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.
Toolchain
Detects hard-coded secrets in Git history and working trees.
Self-hosted automation server with pipelines as code and a large plugin ecosystem.
All-in-one scanner for container images, filesystems, IaC, Kubernetes and SBOMs.
Fast, pattern-based static analysis with thousands of community and security rules.
Source control, merge requests and CI/CD in one platform, with built-in security scanning templates.
After the last part
Two paths pick up where this one stops. Either order works; neither is required.
Scan images, produce SBOMs and ship less, from Dockerfile to registry.
Catch insecure Terraform before it is applied: foundations, Checkov scanning and a merge-request gate.