Trivy Cheat Sheet
Scanner for container images, filesystems, and IaC (Terraform, K8s) for CVEs and misconfigurations.
Overview
Trivy finds vulnerabilities in OS packages and language dependencies in Docker images, repos, and Kubernetes manifests. Use in CI/CD and during container breakout / supply-chain reviews.
Authorized testing only. Use only on systems, networks, and accounts you own or have explicit written permission to test. Unauthorized access is illegal.
Install
sudo apt install -y wget apt-transport-httpswget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo gpg --dearmor -o /usr/share/keyrings/trivy.gpgecho "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.listsudo apt update && sudo apt install -y trivytrivy --versionEssential commands
Scan image
trivy image nginx:latestOnly HIGH/CRITICAL
trivy image --severity HIGH,CRITICAL myapp:1.0Filesystem (running container rootfs export)
trivy fs /path/to/projectCommon workflows
Docker image before deploy —
docker build -t myapp:test .trivy image --ignore-unfixed myapp:testtrivy image -f json -o report.json myapp:testKubernetes manifests —
trivy config deployment.yamltrivy k8s --report summary clusterRepo / lockfiles —
trivy fs --scanners vuln,secret,misconfig .trivy repo https://github.com/org/appSBOM —
trivy image --format cyclonedx -o sbom.json myapp:latestCI exit code on findings —
trivy image --exit-code 1 --severity CRITICAL myapp:prodFlags reference
--severity | Filter CRITICAL,HIGH,... |
|---|---|
--ignore-unfixed | Skip CVEs without patch |
-f table\ | json\ |
--scanners vuln,secret | Scanner types |
--skip-dirs node_modules | Exclude paths |
trivy sbom | Scan existing SBOM |
--db-repository | Offline air-gapped DB |
Tips
- First run downloads vulnerability DB — allow network or pre-cache in CI.
- secret scanner catches hardcoded keys in layers and git history paths.
- Combine with docker history to find secrets in old layers.
- For runtime: export filesystem docker export then trivy fs.