How does Trivy's vulnerability database work, and how do you run Trivy offline?

IntermediateConceptTrivy
Answer

Short answer

Trivy downloads a vulnerability database (built from NVD, distro security trackers, GitHub advisories and more) from an OCI registry and caches it locally; it updates every few hours by default. In air-gapped or rate-limited environments you mirror the DB to an internal registry or download it once and run with --skip-db-update.

Normal behaviour

trivy image nginx:1.27          # first run downloads ~60 MB DB to ~/.cache/trivy

CI tips

  • Cache ~/.cache/trivy between runs to save time and avoid rate limits.
  • Use a mirror:
    trivy image --db-repository registry.company.com/aquasecurity/trivy-db:2 \
                --java-db-repository registry.company.com/aquasecurity/trivy-java-db:1 \
                shop-api:1.4.0
    

Air-gapped

# on a connected machine
oras pull ghcr.io/aquasecurity/trivy-db:2          # get db.tar.gz
# copy to the air-gapped host, extract into ~/.cache/trivy/db/
trivy image --skip-db-update --offline-scan shop-api:1.4.0

Why results change without code changes

The DB updates as new CVEs are published, so yesterday's green image can be red today — that's why scheduled rescans of deployed images matter.

What to say in the interview

"Trivy pulls a regularly updated vulnerability DB from an OCI registry. In CI we cache it or point to an internal mirror to avoid rate limits; air-gapped setups load the DB manually with skip-db-update and offline-scan. Because the DB changes, we rescan running images on a schedule."

All Security Tools questions Roadmap: Trivy — image, file system & IaC scanning

More on Trivy