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.
Diagram
Scanning an image before it ships
Step 1 of 4
Scan
Run the scanner against the built image.
$ 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.
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.
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.
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-31Check yourself
Recognition and the fix. Nothing here is a procedure.
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.