| |

Docker 51 🐳 Docker Image Vulnerability Scanning: Trivy, Grype, and Docker Scout

⏱️ Estimated read: 14 min | |

A Docker image is not a single artifact. It is a stack of layers: a base operating system with its package manager, a language runtime with its dependency tree, and the application code itself. Each layer carries its own inventory of packages, and any one of them can contain a known vulnerability. Scanning exists to walk that stack, extract the package inventory, and match every name and version against vulnerability databases. Three tools dominate the open-source and free-tier space: Trivy, Grype, and Docker Scout. Each approaches the problem differently, and the right choice depends less on raw capability than on workflow and tolerance for false positives.

Key point: No scanner is authoritative. Trivy and Grype query different vulnerability databases and use different matching logic, so they disagree on the same image. Running one scanner is a habit; understanding its philosophy is what prevents a false sense of security.


Why image scanning is not optional

The hidden dependency problem. A base image pulled from Docker Hub contains hundreds of packages the application never explicitly asked for. A python:3.11 image inherits a Debian base with its own libc, curl, and openssl versions, each with its own CVE history. A transitive dependency added by npm install or pip install brings its own vulnerabilities, and the developer may never see the package name. Scanning surfaces what the build process silently included.

The Log4Shell lesson. CVE-2021-44228 hid in Java base images and application layers for years before teams started scanning. The vulnerability was in a transitive dependency that many teams did not know they had. Without scanning, there was no way to answer “am I affected?” until the tooling existed to ask the question.

The immutable tag illusion. A tag like python:3.11 is mutable. The maintainers can push a new image under the same tag tomorrow, and the next build pulls different bits than the last scan approved. Scanning a tag once does not guarantee the image that ships is the image that was scanned. Pinning by digest is the fix, but scanning is what makes the digest meaningful.

The compliance problem. Security frameworks increasingly require evidence of vulnerability management. A scan report with a timestamp and a digest is evidence. A build that passes without a scan is not.

The triage problem. A scan that produces a thousand findings is not useful. The value of a scanner is not just detecting CVEs but prioritizing them: which are critical, which have fixes available, which are actually exploitable in the application’s context. The tools differ in how they handle this prioritization.


a. Trivy

Trivy, maintained by Aqua Security, is a single static binary with no external dependencies. It scans container images, filesystems, Git repositories, and Kubernetes clusters for vulnerabilities, misconfigurations, and secrets .

Installation and basic usage

# macOS
brew install trivy

# Or run from a container
docker run --rm aquasec/trivy image nginx:latest

# Scan an image
trivy image nginx:1.25

The scan pulls the image, unpacks the layers, parses the package databases, and matches installed versions against its vulnerability database .

Filtering by severity

trivy image --severity HIGH,CRITICAL nginx:1.25

The severity filter narrows the output to actionable findings. For daily workflows, focusing on HIGH and CRITICAL is the common pattern .

Excluding unfixed vulnerabilities

trivy image --ignore-unfixed --severity CRITICAL nginx:1.25

Many CVEs have no fix available yet. --ignore-unfixed excludes them from the report, which is useful for build gates where the goal is to block only what can be remediated .

Failing builds on findings

trivy image --severity CRITICAL --exit-code 1 nginx:1.25

The --exit-code 1 flag makes Trivy return a non-zero exit code when findings match the severity filter. This is the mechanism that turns a scan into a build gate .

The false positive trade-off

Trivy is more aggressive on inclusion. It flags CVEs based on package version numbers, even when a distribution has backport-patched the vulnerability without bumping the version string. Red Hat and Debian frequently do this. The result is higher recall but a higher false positive rate. In an internal test of 500 enterprise images, Trivy produced about 18% more findings than Grype, and roughly 60% of those extra findings were false positives from backport patches .

When Trivy is the right choice

Trivy is the right default when the operational pain is missing a real CVE, not alert volume. Its single-binary design makes it easy to drop into CI runners. Its database refreshes every six hours, which gives it a slight edge during fast-moving disclosure windows .


b. Grype

Grype, maintained by Anchore, is a vulnerability scanner for container images and filesystems. It is designed to work with Syft, Anchore’s SBOM generation tool, and it emphasizes threat prioritization through EPSS and KEV data .

Installation and basic usage

# Quick install
curl -sSfL https://get.anchore.io/grype | sudo sh -s -- -b /usr/local/bin

# Scan an image
grype alpine:latest

# Scan an SBOM
grype sbom:./sbom.json

Grype can scan directly from a registry without a container runtime, and it accepts SBOMs as input for faster subsequent scans .

Prioritization with EPSS and KEV

Grype’s default output sorts by a risk score that combines CVSS severity with EPSS (Exploit Prediction Scoring System) and KEV (Known Exploited Vulnerabilities) data. A CVE that is being actively exploited in the wild is surfaced above a CVE with the same CVSS score that has no known exploitation .

The false positive reduction

Grype’s handling of distro-specific patch metadata has improved since version 0.79. It is noticeably quieter on Red Hat and Ubuntu base images, where backport patches are common. For teams whose operational pain is alert volume, Grype’s defaults reduce noise .

SBOM-first workflows

Grype pairs with Syft, which generates SBOMs in SPDX and CycloneDX formats. The workflow is: generate the SBOM once with Syft, then scan it with Grype. This is efficient for batch scanning and for workflows where the SBOM is shared across multiple downstream tools .

When Grype is the right choice

Grype is the right choice when alert volume is the problem. Its prioritization is better suited to teams that need to triage findings rather than receive a comprehensive list. The SBOM-first architecture fits supply-chain workflows where the inventory is a first-class artifact .


c. Docker Scout

Docker Scout is Docker’s integrated scanning service. It is built into Docker Desktop and the docker scout CLI, and it analyzes images pushed to Docker Hub or integrated registries .

Enabling and scanning

# Sign in
docker login

# Enroll your organization
docker scout enroll ORG_NAME

# Analyze an image
docker scout cves nginx:latest

# Quick overview
docker scout quickview nginx:latest

Scout analyzes local images by default. For remote repositories, image analysis must be enabled on the repository .

Policy evaluation

Scout’s distinguishing feature is policy evaluation. Beyond listing CVEs, it evaluates images against policies defined in the organization’s configuration. A policy can require that no critical vulnerabilities are present, that the base image is up to date, or that specific packages meet version requirements .

VEX and provenance

Scout reads VEX (Vulnerability Exploitability eXchange) statements from build attestations. If a base image has a VEX statement suppressing a CVE that is not actually exploitable in the application’s context, Scout applies it. This reduces false positives for images built from hardened bases .

When Docker Scout is the right choice

Scout is the right choice when the workflow is already centered on Docker Hub and Docker Desktop. It integrates with the registry, it provides a dashboard, and it evaluates policy rather than just listing findings. The trade-off is that it is less useful outside the Docker ecosystem .


Complete Example Session

# ============================================
# PART 1: TRIVY — BASIC SCAN
# ============================================

trivy image nginx:1.25

# Output:
# nginx:1.25 (debian 12.4)
# Total: 84 (UNKNOWN: 0, LOW: 32, MEDIUM: 41, HIGH: 9, CRITICAL: 2)
# ...

# ============================================
# PART 2: TRIVY — SEVERITY FILTER
# ============================================

trivy image --severity HIGH,CRITICAL nginx:1.25

# ============================================
# PART 3: TRIVY — BUILD GATE
# ============================================

trivy image --severity CRITICAL --exit-code 1 --ignore-unfixed nginx:1.25

# Exit code 1 if CRITICAL CVEs with fixes are found.

# ============================================
# PART 4: GRYPE — BASIC SCAN
# ============================================

grype alpine:latest

# Sorted by risk score by default.
# KEV entries surfaced at the top.

# ============================================
# PART 5: GRYPE — SORT BY EPSS
# ============================================

grype alpine:latest --sort-by epss

# ============================================
# PART 6: GRYPE — SBOM SCAN
# ============================================

# Generate SBOM with Syft
syft alpine:latest -o spdx-json > sbom.json

# Scan the SBOM
grype sbom:./sbom.json

# ============================================
# PART 7: DOCKER SCOUT — QUICKVIEW
# ============================================

docker scout quickview nginx:latest

# Your image  nginx:latest  │    0C     2H     8M     1L
# Base image  debian:12     │    0C     1H     4M     0L

# ============================================
# PART 8: DOCKER SCOUT — CVES
# ============================================

docker scout cves --only-severity critical nginx:latest

# ============================================
# PART 9: DOCKER SCOUT — COMPARE
# ============================================

docker scout compare --to nginx:1.24 nginx:1.25

# ============================================
# PART 10: CI/CD INTEGRATION
# ============================================

# GitHub Actions with Trivy:
# - name: Scan image
#   uses: aquasecurity/trivy-action@master
#   with:
#     image-ref: myapp:${{ github.sha }}
#     format: sarif
#     output: trivy-results.sarif
#     severity: CRITICAL

# - name: Upload SARIF
#   uses: github/codeql-action/upload-sarif@v2
#   with:
#     sarif_file: trivy-results.sarif

The ten parts walked through basic scans, severity filtering, build gates, Grype’s prioritization, SBOM workflows, Scout’s quickview and comparison, and CI/CD integration. The same nginx and alpine images ran through every part, showing how each tool presents findings.


Quick Reference

Scanner Comparison

FeatureTrivyGrypeDocker Scout
MaintainerAqua SecurityAnchoreDocker
BinarySingle staticSingle staticDocker CLI plugin
DB refresh6 hours12 hoursContinuous
False positive rateHigherLowerLower (VEX-aware)
PrioritizationSeverityRisk score, EPSS, KEVPolicy, VEX
SBOM integrationBuilt-inSyftAttestations
CI/CDAction availableAction availableAction available
Best forRecallTriageDocker ecosystem

Common Commands

ToolCommandPurpose
Trivytrivy image <img>Scan image
Trivytrivy image --severity HIGH,CRITICAL <img>Filter severity
Trivytrivy image --exit-code 1 <img>Fail on findings
Grypegrype <img>Scan image
Grypegrype --sort-by epss <img>Sort by threat
Grypegrype sbom:./sbom.jsonScan SBOM
Scoutdocker scout quickview <img>Overview
Scoutdocker scout cves <img>List CVEs
Scoutdocker scout compare --to <old> <new>Compare

Severity Levels

LevelMeaning
CRITICALExploitable remotely, severe impact
HIGHSignificant impact
MEDIUMModerate impact
LOWMinimal impact
UNKNOWNNot yet scored

Best Practices

✅ Do This:

# Scan the final image, not the source code.
trivy image myapp:latest  # ✅

# Pin base images by digest.
FROM python:3.11@sha256:abc123...  # ✅

# Use --exit-code in CI/CD to gate builds.
trivy image --exit-code 1 --severity CRITICAL myapp:latest  # ✅

# Scan SBOMs for faster subsequent scans.
grype sbom:./sbom.json  # ✅

# Run both Trivy and Grype for cross-validation.
# Disagreements are meaningful signals.  # ✅

# Use minimal or distroless base images.
FROM gcr.io/distroless/python3  # ✅

# Scan registry images on a schedule.
# New CVEs are disclosed continuously.  # ✅

❌ Don’t Do This:

# Don't scan only the base image.
trivy image python:3.11  # ❌ Misses application dependencies

# Don't rely on a mutable tag.
FROM python:3.11  # ❌ Tag can change

# Don't ignore the "Fixed Version" column.
# Upgrading the package is the fastest remediation.  # ❌

# Don't treat one scanner's output as complete.
# Trivy and Grype disagree on the same image.  # ❌

# Don't skip scanning because the image is "internal."
# Internal images pull public base layers.  # ❌

# Don't set the severity threshold too low.
# --severity LOW produces noise that hides critical findings.  # ❌

Common Pitfalls

PitfallWhy It HappensFix
False positivesBackport patches without version bumpUse Grype or accept triage effort
Missing CVEsScanner database lagRefresh DB, use multiple scanners
Build not gatedNo --exit-codeAdd exit code to CI step
Scan of stale imageTag changed after scanPin by digest
Alert fatigueThreshold too lowFilter to HIGH,CRITICAL
SBOM not usedRegenerated per scanGenerate once, scan repeatedly
Registry scan disabledScout not enabledEnable image analysis on repo

Real-World Examples

1. Trivy Basic Scan

trivy image nginx:latest

2. Trivy Severity Filter

trivy image --severity HIGH,CRITICAL nginx:latest

3. Trivy Build Gate

trivy image --exit-code 1 --severity CRITICAL --ignore-unfixed myapp:latest

4. Grype Basic Scan

grype alpine:latest

5. Grype Sort by EPSS

grype alpine:latest --sort-by epss

6. Grype SBOM Scan

grype sbom:./sbom.json

7. Docker Scout Quickview

docker scout quickview nginx:latest

8. Docker Scout CVEs

docker scout cves --only-severity critical nginx:latest

9. Docker Scout Compare

docker scout compare --to nginx:1.24 nginx:1.25

10. CI/CD Trivy Action

- uses: aquasecurity/trivy-action@master
  with:
    image-ref: myapp:${{ github.sha }}
    severity: CRITICAL
    exit-code: '1'

Visual

The Image Stack

┌────────────────────────────────────────────────────────────┐
│  WHAT SCANNING FINDS                                       │
│                                                            │
│  ┌──────────────────────────────────────────────────┐     │
│  │  APPLICATION CODE                                 │     │
│  │    Your own code. Scanned for embedded secrets.   │     │
│  └──────────────────────────────────────────────────┘     │
│                        │                                   │
│                        v                                   │
│  ┌──────────────────────────────────────────────────┐     │
│  │  LANGUAGE DEPENDENCIES                            │     │
│  │    node_modules, site-packages, vendor/           │     │
│  │    Tracked through lockfiles.                     │     │
│  └──────────────────────────────────────────────────┘     │
│                        │                                   │
│                        v                                   │
│  ┌──────────────────────────────────────────────────┐     │
│  │  BASE OS PACKAGES                                 │     │
│  │    libc, openssl, curl, apt/apk/yum               │     │
│  │    Tracked through distro package database.       │     │
│  └──────────────────────────────────────────────────┘     │
│                        │                                   │
│                        v                                   │
│  ┌──────────────────────────────────────────────────┐     │
│  │  VULNERABILITY DATABASES                          │     │
│  │    NVD, GHSA, OSV, distro trackers                │     │
│  │    Each scanner queries a subset.                 │     │
│  └──────────────────────────────────────────────────┘     │
│                                                            │
│  A scan that misses any layer produces a partial answer.   │
│                                                            │
└────────────────────────────────────────────────────────────┘

Trivy vs Grype Philosophy

┌────────────────────────────────────────────────────────────┐
│  SCANNER PHILOSOPHY                                        │
│                                                            │
│  TRIVY (recall-focused)                                    │
│  ┌──────────────────────────────────────────────────┐     │
│  │  Aggressive inclusion.                            │     │
│  │  Flags CVEs by version number.                    │     │
│  │  Higher false positives on backport patches.      │     │
│  │  Better for: not missing a real CVE.              │     │
│  └──────────────────────────────────────────────────┘     │
│                                                            │
│  GRYPE (precision-focused)                                 │
│  ┌──────────────────────────────────────────────────┐     │
│  │  Smarter distro patch handling.                   │     │
│  │  Prioritizes by EPSS and KEV.                     │     │
│  │  Lower false positives.                           │     │
│  │  Better for: reducing alert volume.               │     │
│  └──────────────────────────────────────────────────┘     │
│                                                            │
│  The choice is a trade-off, not a correctness question.    │
│  Run both for cross-validation.                            │
│                                                            │
└────────────────────────────────────────────────────────────┘

Build Gate

┌────────────────────────────────────────────────────────────┐
│  BUILD GATE WITH SCANNING                                  │
│                                                            │
│  ┌─────────┐                                              │
│  │ BUILD   │                                              │
│  └────┬────┘                                              │
│       │                                                    │
│       v                                                    │
│  ┌──────────────────────────────────────────────────┐     │
│  │  SCAN IMAGE                                       │     │
│  │    trivy image --exit-code 1 --severity CRITICAL  │     │
│  └──────────────────────────────────────────────────┘     │
│       │                                                    │
│       ├───────────────┬──────────────┐                    │
│       │               │              │                    │
│       v               v              v                    │
│  PASS              FAIL           UNSTABLE                │
│  (exit 0)          (exit 1)       (scan error)            │
│       │               │              │                    │
│       v               v              v                    │
│  ┌─────────┐      ┌─────────┐    ┌─────────┐             │
│  │  PUSH   │      │  BLOCK  │    │  REVIEW │             │
│  │         │      │  BUILD  │    │  MANUAL │             │
│  └─────────┘      └─────────┘    └─────────┘             │
│                                                            │
│  A scan without a gate is a report nobody reads.           │
│  A gate without a scan is theater.                         │
│                                                            │
└────────────────────────────────────────────────────────────┘

Prioritization

┌────────────────────────────────────────────────────────────┐
│  GRYPE RISK SCORE                                          │
│                                                            │
│  risk = min(1, threat × average(severity)) × 100           │
│                                                            │
│  ┌──────────────────────────────────────────────────┐     │
│  │  CVSS severity      →  impact if exploited         │     │
│  │  EPSS score         →  likelihood of exploitation  │     │
│  │  KEV flag           →  known exploited in the wild │     │
│  └──────────────────────────────────────────────────┘     │
│                                                            │
│  A CVE with CRITICAL severity but low EPSS ranks below     │
│  a CVE with HIGH severity and high EPSS.                   │
│                                                            │
│  The goal is to surface what is actually being exploited,  │
│  not just what is theoretically severe.                    │
│                                                            │
└────────────────────────────────────────────────────────────┘

Summary

ItemValue
TrivySingle-binary scanner by Aqua; aggressive inclusion
GrypeScanner by Anchore; risk-based prioritization
Docker ScoutDocker’s integrated service; policy and VEX
SBOMSoftware Bill of Materials; inventory of packages
CVECommon Vulnerabilities and Exposures
EPSSExploit Prediction Scoring System
KEVKnown Exploited Vulnerabilities catalog
VEXVulnerability Exploitability eXchange; suppression statements
Build gate--exit-code 1 in CI/CD
Digest pinningImmutable image reference

Key takeaways:

  • A Docker image is a stack of layers, each with its own vulnerability surface. A scan that covers only the base image misses application dependencies. A scan that covers only the lockfile misses OS packages. The scanner walks the whole stack.
  • Trivy and Grype disagree on the same image. They query different databases and use different matching logic. A CVE found by one and not the other is a signal worth investigating, not a tool failure .
  • Trivy is more aggressive; Grype is quieter. Trivy flags CVEs by version number even when a distro has backport-patched the vulnerability. This produces higher recall but more false positives. Grype’s handling of distro patch metadata reduces noise .
  • Docker Scout adds policy and VEX. Beyond listing CVEs, Scout evaluates images against organization policies and applies VEX statements from base images to suppress non-exploitable findings .
  • The scan is only useful if it gates the build. A scan that prints a report is a habit. A scan with --exit-code 1 that blocks a failing build is a control. The gate is what prevents vulnerable images from shipping .
  • Pin base images by digest, not tag. A tag is mutable. The image scanned in CI is not guaranteed to be the image that ships unless the reference is a content hash .
  • Minimal base images reduce what there is to scan. A distroless image has no shell and no package manager. The inventory is smaller, the attack surface is smaller, and the scan produces fewer findings .
  • Run both Trivy and Grype for cross-validation. The extra findings from one tool are not always false positives, and the findings both tools agree on are the ones to prioritize.

Remember: Docker image vulnerability scanning is not a single tool choice. It is a practice of walking the image’s package inventory, matching it against vulnerability databases, and gating the build on the results. Trivy and Grype are the two dominant open-source scanners. Trivy is a single binary with aggressive inclusion and higher recall. Grype prioritizes by risk score, EPSS, and KEV, and its defaults produce less noise. Docker Scout integrates with the Docker ecosystem and adds policy evaluation and VEX suppression. The right approach is to pick one as the primary scanner, run the other for cross-validation, gate the build on critical findings, and treat disagreements between tools as signals to investigate rather than errors to resolve. The scanner is not the security; the gate is. Without a gate, the scan is just a report.


Was this helpful?


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!