Skip to content
intermediate Phase 15 · Docker Security Advanced

Vulnerability Scanning

Scan images with Trivy, Snyk, and Docker Scout for CVEs.

1h
0 problems
Topic Progress 0%

Scanning with Trivy

Scanning with Trivy

Trivy inspects OS packages and language dependencies from a vulnerability database it updates on first run:

trivy image --severity HIGH,CRITICAL --exit-code 1 myapp:1.4
trivy image --format json -o report.json myapp:1.4

--exit-code 1 turns findings into a CI failure; pair it with --severity so informational noise does not block merges. Beyond images, trivy fs . finds secrets and trivy config . lints Dockerfiles and IaC — catching RUN curl | sh and root users before the image is even built.

Snyk, Docker Scout, and Reporting

Snyk, Docker Scout, and Reporting

Tools differ in where analysis runs and what they add:

Tool Invocation Character
Trivy trivy image <img> local, offline-capable DB, CI-friendly
Snyk snyk container test <img> authenticated service, fix guidance, policy thresholds
Docker Scout docker scout cves <img> Docker-native, base-image recommendations
snyk container test myapp:1.4 --severity-threshold=high
docker scout quickview myapp:1.4

Snyk and Scout additionally rank fixes: they tell you that jumping node:20 to a patched digest clears a list of CVEs — the remediation data Trivy's table view lacks.

Pipeline Strategy and Pitfalls

Pipeline Strategy and Pitfalls

Scan the artifact, not just the Dockerfile. The image contains the final dependency tree; a lockfile scan misses OS packages installed by apt-get.

Gate on what you can fix. Failing CI on every HIGH with no available fix freezes the pipeline; fail on fixable criticals, ticket the rest, and re-scan on a schedule against the registry so aging images get re-evaluated as new CVEs appear.

Provenance of a finding. trivy image --debug-packages-style views and docker history attribute a vulnerable package to the layer that installed it — usually the base tag, which is why digest-pinning and regular base bumps are the highest-leverage fix.

Interview: place scanning in the pipeline (build → scan → push), defend your severity gate, and explain how you would handle a CVE with no upstream fix.

Quiz

1. Why scan the built image rather than only the lockfile?

Question 1 options

2. What do --severity HIGH,CRITICAL and --exit-code 1 achieve together in CI?

Question 2 options

3. A critical CVE has no upstream fix. Best immediate response?

Question 3 options

Flashcards

Question

Trivy

Answer

Local CVE scanner for images, filesystem secrets, and IaC configs; --exit-code 1 gates CI.

Question

snyk container test

Answer

Authenticated scanning service adding fix guidance and severity thresholds.

Question

docker scout cves

Answer

Docker-native analysis with base-image upgrade recommendations.

Question

Scan surfaces

Answer

Language dependencies (lockfile) and OS packages (image) — scan both.

Question

Severity gate

Answer

Fail on fixable high/critical; track the rest and re-scan as new CVEs land.

Revision Notes

Key Takeaways

  • 1. Build → scan → push; gate on fixable severities
  • 2. Base image choice drives most OS-package findings
  • 3. Rescan registry images over time, not just at build

Interview Tips

  • • Place each tool (Trivy/Snyk/Scout) in a pipeline step and justify the choice
  • • Explain triage for an unfixable critical without disabling the gate

Cheat Sheet

trivy image --severity HIGH,CRITICAL --exit-code 1 before push; snyk/docker scout for fix guidance; gate fixable only; rescan registry; bump base digests.

Continue Learning

Before You Start

  • No prerequisites listed.