Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 114/ 160
06. Docker Security & Hardening

Image Vulnerability Scanning (docker scout, Trivy, Grype)

Scan images for CVEs in CI with Scout, Trivy, or Grype and gate on severity.

IntermediateTrivy · Scout3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Scan before merge, re-scan the release digest and gate critical/fixable findings under an explicit exception process.

Think of it like…

A scanner is a recalled-parts database: ownership, version and whether that part is installed determine the action, but the notice does not prove how an engine is assembled.

Where you’ve seen it

In practice, trivy image --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed ghcr.io/acme/api@sha256:deadbeef is the concrete move for this job: scan images for CVEs in CI with Scout, Trivy, or Grype and gate on severity. The release is not accepted until save JSON for the exact digest, confirm vulnerability DB timestamp and compare OS/library findings after the fixed base build confirms the result.

Words you’ll hear

Trivy
The implementation control in trivy image --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed ghcr.io/acme/api@sha256:deadbeef for scan images for CVEs in CI with Scout, Trivy, or Grype and gate on severity.
Scout
The result to observe with save JSON for the exact digest, confirm vulnerability DB timestamp and compare OS/library findings after the fixed base build, rather than infer from a successful command alone.
CVE Gate
The production boundary exposed when failing on every Low finding until teams disable scanning, or scanning app:latest in CI and deploying a different digest later.

Visual diagram

Loading interactive diagram

Theory & deep dive

Trivy control path

The concrete mechanism is trivy image --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed ghcr.io/acme/api@sha256:deadbeef. The observable result is save JSON for the exact digest, confirm vulnerability DB timestamp and compare OS/library findings after the fixed base build; if those disagree, inspect the runtime evidence before changing unrelated settings.

Scan images for CVEs in CI with Scout, Trivy, or Grype and gate on severity. Keep Trivy, Scout and CVE Gate in the same deployment record so the intent and the observed state cannot drift apart.

Concrete Trivy setup

trivy image --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed ghcr.io/acme/api@sha256:deadbeef

Key takeaway: Prove Scout with save JSON for the exact digest, confirm vulnerability DB timestamp and compare OS/library findings after the fixed base build, not with command success alone.

CVE Gate failure boundary

Different scanners can report different counts because of CPE/advisory matching, source-package attribution and unsupported distros. A Critical in an unused Python wheel is not automatically worse than an exposed library with known exploitation, while an old digest may be cleaner only because it is stale. The narrow failure to design for is failing on every Low finding until teams disable scanning, or scanning app:latest in CI and deploying a different digest later.

Accept this compromise explicitly: Policy gating is predictable; risk acceptance plus exploitability review is necessary for unpatched transitive vulnerabilities. The controlled check-save JSON for the exact digest, confirm vulnerability DB timestamp and compare OS/library findings after the fixed base build-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: failing on every Low finding until teams disable scanning, or scanning app:latest in CI and deploying a different digest later.

Key takeaway: Policy gating is predictable; risk acceptance plus exploitability review is necessary for unpatched transitive vulnerabilities.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: Different scanners can report different counts because of CPE/advisory matching, source-package attribution and unsupported distros. A Critical in an unused Python wheel is not automatically worse than an exposed library with known exploitation, while an old digest may be cleaner only because it is stale.

Scan before merge, re-scan the release digest and gate critical/fixable findings under an explicit exception process.
Key numbers at this step
Intent
Trivy

When to use it & trade-offs

What it is

Trivy, Grype and Docker Scout compare package inventories and distro advisories with SBOM-like metadata from image layers. Severity and exploitability must be combined with package reachability, fix availability and policy; a scanner’s database age affects results.

Why it matters: Different scanners can report different counts because of CPE/advisory matching, source-package attribution and unsupported distros. A Critical in an unused Python wheel is not automatically worse than an exposed library with known exploitation, while an old digest may be cleaner only because it is stale.

When to reach for it

  • The fit is strongest for this job: scan images for CVEs in CI with Scout, Trivy, or Grype and gate on severity. Pair it with save JSON for the exact digest, confirm vulnerability DB timestamp and compare OS/library findings after the fixed base build in the runbook.
  • Production Trivy changes should make Scout observable through trivy image --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed ghcr.io/acme/api@sha256:deadbeef, rather than trusting the runtime default.
  • Keep a rollback example for the case where failing on every Low finding until teams disable scanning, or scanning app:latest in CI and deploying a different digest later.

When to avoid or be careful

  • Do not accept command success while the system can still fail by failing on every Low finding until teams disable scanning, or scanning app:latest in CI and deploying a different digest later.
  • Avoid erasing CVE Gate protection merely to dodge this cost: “Policy gating is predictable; risk acceptance plus exploitability review is necessary for unpatched transitive vulnerabilities”.
  • Do not replace the evidence path-save JSON for the exact digest, confirm vulnerability DB timestamp and compare OS/library findings after the fixed base build-with a screenshot or a mutable tag.

trivy image --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed ghcr.io/acme/api@sha256:deadbeef: practical choices

Explicit Trivy
Best for: Scan images for CVEs in CI with Scout, Trivy, or Grype and gate on severity, with a reviewed runbook.

Strengths: Trivy, Grype and Docker Scout compare package inventories and distro advisories with SBOM-like metadata from image layers. Severity and exploitability must be combined with package reachability, fix availability and policy; a scanner’s database age affects results.

Watch out: Policy gating is predictable; risk acceptance plus exploitability review is necessary for unpatched transitive vulnerabilities.

Ambient default
Best for: Short-lived Scout experiments with low blast radius.

Strengths: It can begin with trivy image --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed ghcr.io/acme/api@sha256:deadbeef and fewer surrounding controls.

Watch out: It silently accepts failing on every Low finding until teams disable scanning, or scanning app:latest in CI and deploying a different digest later, which makes the result hard to reproduce after promotion.

Managed CVE Gate
Best for: Teams that centralize CVE Gate policy across many workloads.

Strengths: Different scanners can report different counts because of CPE/advisory matching, source-package attribution and unsupported distros. A Critical in an unused Python wheel is not automatically worse than an exposed library with known exploitation, while an old digest may be cleaner only because it is stale.

Watch out: The platform adds an ownership and debugging layer; retain save JSON for the exact digest, confirm vulnerability DB timestamp and compare OS/library findings after the fixed base build as the direct check.

Interview signals & numbers to know

When this topic comes up

  • trivy image --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed ghcr.io/acme/api@sha256:deadbeef
  • save JSON for the exact digest, confirm vulnerability DB timestamp and compare OS/library findings after the fixed base build
  • Failure signature: failing on every Low finding until teams disable scanning, or scanning app:latest in CI and deploying a different digest later
  • Trade-off: Policy gating is predictable; risk acceptance plus exploitability review is necessary for unpatched transitive vulnerabilities.

Benchmarks & rules of thumb

2 scan moments -
pull request and exact release digest
CRITICAL,HIGH -
example deployment gate
0 unfixed -
may mean an unresolved risk rather than permission to ignore

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful trivy image --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed ghcr.io/acme/api@sha256:deadbeef as proof and skipping save JSON for the exact digest, confirm vulnerability DB timestamp and compare OS/library findings after the fixed base build.
  • Failing on every Low finding until teams disable scanning, or scanning app:latest in CI and deploying a different digest later
  • Optimizing Trivy without accepting that policy gating is predictable; risk acceptance plus exploitability review is necessary for unpatched transitive vulnerabilities.

Likely interviewer follow-ups

  • Why does trivy image --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed ghcr.io/acme/api@sha256:deadbeef address Trivy here rather than through application code?
  • How would you distinguish healthy Scout from the failure “failing on every Low finding until teams disable scanning, or scanning app:latest in CI and deploying a different digest later” using save JSON for the exact digest, confirm vulnerability DB timestamp and compare OS/library findings after the fixed base build?
  • When would this trade-off-“Policy gating is predictable; risk acceptance plus exploitability review is necessary for unpatched transitive vulnerabilities”-justify a different CVE Gate design?
Interview tip: Give one concrete operation-trivy image --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed ghcr.io/acme/api@sha256:deadbeef-and one proof-save JSON for the exact digest, confirm vulnerability DB timestamp and compare OS/library findings after the fixed base build. Then name the boundary: failing on every Low finding until teams disable scanning, or scanning app:latest in CI and deploying a different digest later.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Image Vulnerability Scanning (docker scout, Trivy, Grype) with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Avoiding Hardcoded Credentials & Image Layer Secret Leaks
Next topic
Software Bill of Materials (SBOM) Generation (syft, docker sbom)