Container image scanning with Trivy and Grype: reading results and fixing them

Image scanners match OS and language packages against vulnerability databases. How to run Trivy and Grype in CI, read the output, decide what to fix, and shrink findings with smaller base images.

Lesson 15 of 26 · 12 min read · practice only with authorization

Diagram

Scanning an image before it ships

Follow the path. One example at a time.

Step 1 of 4

Scan

Run the scanner against the built image.

Illustration: Scan
$ trivy image --severity HIGH,CRITICAL --ignore-unfixed shop/api:1.42.0
shop/api:1.42.0 (debian 12.5)
Total: 3 (HIGH: 2, CRITICAL: 1)

The example on the open step is one illustration, or the fix you can paste into an application you own.

What this page is made of

3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.

  1. Base image debt

    What fails
    Most findings come from the base image, not your code.
    Who is affected
    Every service using that base.
    What you would notice
    Hundreds of OS package findings in a full distribution image.
    What you change
    Use slim or distroless bases and rebuild on a schedule.
  2. Unfixed findings

    What fails
    Some vulnerabilities have no fixed package yet.
    Who is affected
    Teams blocked by gates they cannot satisfy.
    What you would notice
    Builds failing on findings with no fix.
    What you change
    Gate on fixable issues and track unfixed ones with VEX or expiry-dated ignores.
  3. Scan where it runs

    What fails
    Images in registries age after they were scanned.
    Who is affected
    Running workloads with new CVEs.
    What you would notice
    Images scanned once at build and never again.
    What you change
    Rescan registries and running clusters daily.

Grype as a second opinion

Different scanners use different data sources and matching logic, so results differ. Grype pairs with Syft SBOMs, which lets you scan the SBOM later without pulling the image again.

$ grype shop/api:1.42.0 --fail-on high
$ syft shop/api:1.42.0 -o syft-json > api.syft.json && grype sbom:api.syft.json

Ignoring responsibly

When a finding does not apply, record why and set an expiry date so it is reviewed again.

# .trivyignore.yaml
vulnerabilities:
  - id: CVE-2023-45853
    paths: ["usr/lib/x86_64-linux-gnu/libz.so.1"]
    statement: "minizip not used; zlib core only"
    expired_at: 2027-01-31

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

Most findings come from OS packages in the base image. What helps most?

Sibling techniques

Pages at the same depth, plus a lab and a glossary card for this one.

This page stands on its own. The lab and the glossary card are the next reading.

Practice

  1. LabTerminal mission: Which critical findings can be fixed todayA Trivy image report has criticals in the OS layer and the app. Use jq to separate fixable from unfixable, and say which ones a rebuild fixes and which need a code change.