Container Security
Scan container images for vulnerable packages and misconfiguration, and harden how images are built.
BeginnerContainer Image ScanningContainerSupply Chain
Where it fits in the lifecycle
- Plan
- Code
- Build
- Test
- Release
- Deploy
- Operate
- Monitor
- Build Dependency scanning, image scanning, SBOM generation and signing.
- Deploy Policy enforcement, admission control and infrastructure security.
Overview
Container images bundle an OS userland plus application dependencies. Image scanning enumerates those layers and reports known vulnerabilities; image hardening reduces what is there to exploit in the first place.
Why it matters
A base image chosen once can propagate vulnerable packages to every service. Scanning at build time keeps the blast radius visible and small.
How it works
- 01The scanner reads the image manifest and extracts package databases per layer.
- 02Packages are matched against distribution and language advisories.
- 03Dockerfile checks flag root users, missing pinning and secrets in layers.
- 04Registry-side scanning re-evaluates images as new advisories are published.
Common tools
TrivyGrypeClairDocker ScoutDockerPodmanKubernetesOpenShift
Implementation examples
yamlScan an image in CI
container_scan: stage: security script: - trivy image --exit-code 1 --severity CRITICAL --ignore-unfixed $IMAGE_NAMEdockerfileMinimal, non-root Dockerfile
FROM python:3.12-slim AS baseRUN useradd --uid 10001 --create-home appWORKDIR /appCOPY --chown=app:app requirements.txt .RUN pip install --no-cache-dir -r requirements.txtCOPY --chown=app:app . .USER 10001CMD ["python", "-m", "app"]Best practices
- Rebuild regularly so base-image fixes actually reach production.
- Pin base images by digest and keep a small set of approved bases.
- Scan in CI and continuously in the registry.
Common mistakes
- Scanning only at build time and never rescanning stored images.
- Building with secrets passed as build args, which persist in layer history.
Hands-on labs
- Lab 01 — Scan a Container Image
Scan a public container image with Trivy and interpret the findings.
- Lab 06 — Build a Secure CI/CD Pipeline
Assemble a pipeline containing SAST, SCA, secret detection, container scanning, SBOM generation and a security gate.
- Lab 10 — Triage Vulnerability Findings
Take raw scanner output and produce a prioritised, owner-assigned remediation list.