This is a complete, hands-on Trivy cheat sheet: install, configure, operate, automate and secure it - with copy-paste commands grouped by task. Bookmark it for day-to-day work, incidents and interviews alike.
Trivy is an open-source security scanner that finds CVEs, misconfigurations, secrets and license issues across container images, filesystems, Git repos, IaC and live Kubernetes clusters.
Why you reach for it
- One tool for images, IaC, secrets and Kubernetes scanning
- Fast, with an easy exit-code gate for CI
- No account or SaaS required to get started
Installation
brew install trivy # or: docker run aquasec/trivy
trivy --versionConfiguration reference
Config file to fail only on HIGH/CRITICAL and ignore unfixed CVEs.
# trivy.yaml
severity:
- HIGH
- CRITICAL
vulnerability:
ignore-unfixed: true
exit-code: 1Core commands you use daily
trivy image ghcr.io/acme/web:1.0
trivy fs --scanners vuln,secret,misconfig .
trivy k8s --report summary clusterScan everything
trivy image ghcr.io/acme/web:1.0
trivy fs --scanners vuln,secret,misconfig .
trivy config . # IaC misconfig
trivy repo https://github.com/acme/app
trivy k8s --report summary clusterGating & SBOM
trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 app:1.0
trivy image --format cyclonedx -o sbom.json app:1.0
trivy --download-db-onlyUse it in CI/CD
Fail the build on fixable high/critical CVEs.
- uses: aquasecurity/trivy-action@0.24.0
with:
image-ref: ghcr.io/${{ github.repository }}:${{ github.sha }}
severity: HIGH,CRITICAL
ignore-unfixed: true
exit-code: 1Best-practice checklist
- Gate on HIGH/CRITICAL with ignore-unfixed, then tighten over time
- Scan images, IaC and filesystems - not just one surface
- Cache and periodically refresh the DB in CI
Common pitfalls to avoid
- Failing on unfixed CVEs and drowning in noise
- Scanning only images and ignoring IaC and secrets
- Never updating the vulnerability DB in air-gapped runners
Security quick wins
- Add Trivy as a required check on pull requests
- Generate SBOMs (CycloneDX/SPDX) for supply-chain visibility
Works well with
- Docker - Package an app and its dependencies into a portable image that runs the same everywhere.
- HashiCorp Vault - Secrets management, dynamic credentials and encryption-as-a-service with tight access control.
- SonarQube - Continuous code quality and security analysis with quality gates that block risky merges.
A cheat sheet is muscle memory on paper - keep it close until the commands live in your fingers.
Want senior help putting Trivy to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.