Cloud & app security

Docker Image Vulnerability Scanning: Trivy, Grype and CI Gates

A Docker image can carry hundreds of known vulnerabilities before your code even runs. Scanning at build time, on push and on a schedule is how teams catch them.

Cysoro Security TeamPublished · 8 min read
myapp:1.4.2! CVE-2026-0001 HIGHfixed in 2.4.1 SCAN PASSED: 0 CRITICAL CLOUD & APP SECURITY Docker imagescanning Catch the CVE before production does.
Quick answer

Docker image vulnerability scanning inventories every OS and language package inside an image, matches each one against vulnerability databases such as NVD and distro advisories, and reports the CVEs it finds with a severity and a fixed version. Tools such as Trivy, Grype and Docker Scout do this in seconds, and teams wire them into CI so builds fail on fixable high and critical findings before the image reaches production.

Key takeaways

  • Scanning matches an image inventory against CVE databases; it cannot find unknown or runtime-only flaws.
  • Gate CI on fixable high and critical findings, and rescan on a schedule because new CVEs appear daily.
  • The fastest fix is usually a newer base image; minimal and distroless images shrink the problem first.

Every Docker image is a stack of other people's software: an operating system, system libraries, a language runtime and your dependencies. Any layer can carry a known vulnerability, and the image will run it happily unless someone checks first.

What is Docker image vulnerability scanning?

Docker image vulnerability scanning is the automated inspection of a container image to find known vulnerabilities in the packages it contains. The scanner inventories every package, matches it against vulnerability databases, and reports each CVE with a severity and a fixed version.

A scanner works in three steps. First it unpacks the image layers and builds an inventory: OS packages from the dpkg, apk or rpm database, plus language packages such as npm modules and Python site-packages.

Then it matches that inventory against advisories from NVD, OSV and distro security teams. Finally it filters the matches by severity and fix status and reports them, or fails the build if you told it to.

That inventory step is the same job as generating an SBOM, a software bill of materials. Grype and Docker Scout can scan an SBOM file directly instead of the image, which is useful when you want to rescan a release later without rebuilding it.

How an image scanner works1Unpack layersevery layer,not just the top2InventoryOS + languagepackages3Match CVEsNVD, OSV,distro advisories4Filterseverity, fixstatus, ignores5Decidepass, fail orreport onlyA scanner only knows published CVEs. It cannot find zero-days or flaws in your own code.
How an image scanner turns layers into a pass or fail decision. Illustration by Cysoro.

Why does image scanning matter?

It matters because vulnerable and outdated components are one of the OWASP Top 10 risks, and containers make the problem easy to ignore. An image built once and deployed everywhere spreads one vulnerable library to every environment at once.

The age of the base image is usually the biggest factor. A current slim base image may carry a few dozen findings; an end-of-life base image can carry more than a thousand, including critical ones with no fix because the distribution no longer publishes updates. Scanning makes that difference visible before production does.

Scanning also gives you evidence. When a new CVE is announced, a stored SBOM tells you in minutes whether any running image contains the affected package, instead of guessing or rescanning everything by hand. That speed is what turns a security announcement into a short, calm fix.

Trivy vs Grype vs Docker Scout: which should you use?

Trivy, Grype and Docker Scout all do the same core job, so pick on workflow rather than on vulnerability counts, which overlap heavily. Trivy is the one-binary option if you also want secret and Dockerfile checks; Grype pairs with Syft for SBOM-first work; Scout is the natural choice if you already build with Docker.

CapabilityTrivyGrypeDocker Scout
Built byAqua SecurityAnchoreDocker
Scans besides CVEsSecrets, misconfigurations, licensesNone; pairs with Syft for SBOMsSBOM output
Basic commandtrivy image myapp:latestgrype myapp:latestdocker scout cves myapp:latest
Fail the build--exit-code 1--fail-on high--exit-code
Only fixable issues--ignore-unfixed--only-fixed--only-fixed
SBOMBuilt inVia Syftdocker scout sbom
CostFree, open sourceFree, open sourceFree tier; paid plans for teams

Trivy is a single binary with no daemon, and it covers OS packages, language dependencies, misconfigurations and secrets in one tool. Its first run downloads a vulnerability database, which is cached locally afterwards.

Grype, documented in the Anchore Grype repository, focuses on vulnerability matching and uses direct, CPE-based and indirect dependency matching to keep false positives low. Docker Scout integrates with Docker Desktop and the Docker Hub registry, and its --ignore-base flag splits base-image findings from your own layer findings.

Running two scanners on critical images catches what either misses, because their databases and heuristics differ. If you only run one, Trivy broader coverage gives it the edge for most teams; if SBOM generation and compliance matter most, add Grype and Syft.

How do you run your first scan?

Run your first scan locally against a public image, then against your own image, so you learn to read the output before you wire it into CI. Install Trivy or Grype from the official releases, then scan.

For Trivy, the basic commands are trivy image nginx:1.27 for a full report, and trivy image --severity HIGH,CRITICAL --exit-code 1 myapp:latest to fail only on serious findings. The output lists each vulnerable package, its CVE ID, severity, installed version and fixed version when one exists.

For Grype, run grype myapp:latest, or generate an SBOM first and scan it separately with syft myapp:latest -o cyclonedx-json | grype. For Docker Scout, run docker scout cves myapp:latest from Docker Desktop 4.17 or later, or with the standalone Scout CLI, as described in the Docker Scout documentation.

Read the summary line first: it gives the total count by severity. Then look at the critical findings, check whether a fixed version exists, and note whether the vulnerable package is in your base image or in a dependency you added. That distinction decides who fixes it.

How do you gate CI so vulnerable images never ship?

Gate CI on what you can act on: high and critical findings that have a fix available. Report the rest instead of blocking on it, or teams will learn to bypass the gate.

A Trivy gate looks like this: trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 myapp:1.4.2. The matching Grype command is grype myapp:1.4.2 --fail-on high --only-fixed, and Docker Scout uses docker scout cves --only-severity critical,high --only-fixed --exit-code myapp:1.4.2. Without the exit-code flag, Trivy prints its findings and exits successfully no matter how many critical vulnerabilities it found, so the flag is what turns a report into a gate.

Scan on every pull request, not just before a production release, so a vulnerable base image never gets merged. Scan on push to the main branch, and scan on a schedule — daily is a good default — because CVEs are published daily and an image that was clean two weeks ago can be vulnerable today. The scheduled scan should pull the same tag you run in production.

Send scan results somewhere people will see them. Trivy can output JSON or SARIF for GitHub code scanning, and Docker Scout can output SARIF too. A report that only lives in a CI log is a report nobody reads.

How do you fix what the scanner finds?

Fix findings in order of leverage: update the base image, update the vulnerable dependency, then remove what you do not need. Most findings disappear with the first step alone.

Start with the base image. Move to a current, supported tag, prefer slim or Alpine variants, and pin the image by digest in CI so a rebuild does not silently change the base. Then update the specific package or dependency to its fixed version and rebuild. If the finding is in a package you installed for debugging, remove it from the production image with a multi-stage build.

When a finding has no fix, check whether the vulnerable code is reachable. If your image never calls the affected function, record an accepted risk with a reason and an expiry date, and recheck it later. Trivy supports a .trivyignore file for this, and Grype supports ignore rules and OpenVEX documents. An ignore without an expiry date never gets revisited, so always include one.

Do not ignore findings by editing the scanner config to hide them. That is the same as not scanning, except it costs more time and creates a false sense of safety.

What are the best practices for image scanning?

The best practices are simple, but they only work together: scan early, scan often, use minimal images, and treat findings as work to schedule rather than noise to silence.

  • Shift left. Scan on every pull request and in the Dockerfile review, not only before release.
  • Scan every layer. Secrets and vulnerable packages are often baked into earlier build layers, not only the top one.
  • Use minimal base images. Distroless or Alpine-based images carry fewer packages, shrinking what a scanner and an attacker have to work with.
  • Run as non-root. A container that runs as a non-root user limits what an exploited vulnerability can do.
  • Pin versions and digests. Pin base images and dependencies so rebuilds are reproducible and a new CVE can be traced to a specific version.
  • Store SBOMs. Keep the SBOM with the image so you can answer "are we affected?" in minutes when a new CVE lands.
  • Rescan in the registry. Schedule registry scans so deployed images are rechecked as new advisories appear.
  • Verify the scanner itself. Pin scanner versions and actions by digest in CI, and keep the vulnerability database fresh.

Images are only one part of a secure deployment. Our guide to the difference between HTTP and HTTPS explains the transport security your containers still need in front of them.

NIST SP 800-190, the Application Container Security Guide, recommends scanning images for vulnerabilities before deployment and continuously monitoring for new ones. That guidance is the standard to measure your pipeline against, and the Trivy documentation is a good place to start implementing it.

Scan at every stage, not just oncePull requestscan the diff,block bad baseBuildfail on fixableHIGH / CRITICALPushstore SBOMwith the imageRegistryrescan daily:new CVEs appearA clean scan is a snapshot. It expires the moment a new CVE is published.Keep the gate strict, and keep the ignore list short and dated.
Where scanning belongs in the container lifecycle. Illustration by Cysoro.

What can image scanning not catch?

Image scanning cannot catch everything, and pretending otherwise is dangerous. It only finds known vulnerabilities with published advisories, so zero-days, flaws in your own application code and misconfigurations it does not check for will pass a scan cleanly.

It also cannot see runtime behavior. A container that runs as root, mounts the Docker socket, or talks to the internet without restriction is risky even with zero CVEs. Runtime monitoring, least-privilege configuration and network policy cover the ground scanning cannot.

False positives happen too: a scanner may flag a package that is installed but never loaded, or a vulnerability in a function your image never calls. That is why severity alone is a poor priority order. Use exploitability data such as EPSS and the CISA Known Exploited Vulnerabilities catalog to decide which findings to fix first, and record your reasoning for the ones you accept.

For a wider starting point, our small business cybersecurity checklist covers scanning alongside backups, updates and device security.

The bottom line

Docker image scanning is a small habit with a large payoff: inventory the image, match it against CVE databases, and block fixable high and critical findings before they reach production. Trivy, Grype and Docker Scout all do this well, so pick the one that fits your pipeline and start scanning on every pull request.

Keep the base image current, keep the ignore list short and dated, and rescan on a schedule. A clean scan today is only a snapshot, and the next CVE is already on its way. You can check the public side of the same habit — your site headers and TLS — with our free security headers checker.

Frequently asked questions

What is Docker image vulnerability scanning?

It is the automated inspection of a container image to find known vulnerabilities in the packages it contains. The scanner builds an inventory of OS and language packages, then matches each one against vulnerability databases and reports CVEs with severity and fixed versions.

What is the difference between Trivy and Grype?

Trivy is a single binary from Aqua Security that scans images, filesystems and IaC for vulnerabilities, secrets and misconfigurations. Grype from Anchore focuses on vulnerability matching and pairs with Syft for SBOM generation. Their databases and heuristics differ slightly, so running both can catch findings the other misses.

Should I scan Docker images in CI or in the registry?

Do both. Scan in CI so a vulnerable image never gets merged or pushed, and scan in the registry on a schedule so images that were clean at build time are rechecked when new CVEs are published. A clean image from two weeks ago can be vulnerable today.

What severity should fail a build?

Most teams fail the build on fixable high and critical findings. Failing on every medium or low finding creates noise that teams learn to ignore, and failing on findings with no fix available blocks work nobody can fix. Report the rest and track it separately.

Can a scanner find all vulnerabilities in an image?

No. Scanners only find known vulnerabilities with published advisories. They cannot find zero-days, flaws in your own application code, misconfigurations they do not check for, or runtime attacks. Use scanning alongside code review, dependency updates and runtime monitoring.

How do I fix vulnerabilities found in a Docker image?

Update the base image first, then update the vulnerable package or dependency to a fixed version, and rebuild. If no fix exists, check whether the vulnerable code is reachable in your image; if it is not, record an accepted risk with an expiry date and recheck it later.

What is an SBOM and why does it matter for scanning?

An SBOM, or software bill of materials, is a complete inventory of the components in an image. Scanners build one internally, and storing it lets you rescan later without the image, prove what was in a release, and respond quickly when a new CVE is announced.

Does scanning slow down my CI pipeline?

A first scan downloads a vulnerability database, which takes a minute or two, but later scans are usually under a minute for a typical image. Caching the database and scanning only the images you build keeps the cost small compared with the cost of shipping a known critical CVE.

Sources

  1. Aqua Security — Trivy Documentation
  2. Anchore — Grype Documentation
  3. Docker — Docker Scout Documentation
  4. NIST — SP 800-190 Application Container Security Guide
  5. OWASP — OWASP Top 10:2021 (Vulnerable and Outdated Components)
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against Trivy, Grype and Docker Scout documentation, NIST SP 800-190 and the OWASP Top 10:2021.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free