ScriptsApr 10, 2026·3 min read

Trivy — All-in-One Security Scanner for Containers & Code

Trivy is an open-source, comprehensive security scanner that finds vulnerabilities, misconfigurations, secrets, and SBOM issues in containers, Kubernetes, code repos, and clouds.

TL;DR
Trivy finds vulnerabilities, misconfigurations, and secrets across containers, code, and Kubernetes in one scan.
§01

What it is

Trivy is an open-source security scanner by Aqua Security that detects vulnerabilities in OS packages and language dependencies, misconfigurations in Terraform and Dockerfiles, leaked secrets like API keys, and SBOM issues -- all from a single binary with zero configuration. It scans Docker images, Git repositories, Kubernetes clusters, and local filesystems.

Trivy targets DevSecOps engineers, platform teams, and developers who need security scanning integrated into CI/CD pipelines without managing multiple specialized tools.

§02

How it saves time or tokens

Trivy consolidates what used to require four or five separate tools (vulnerability scanner, secret detector, IaC linter, SBOM generator, Kubernetes auditor) into one binary. A single trivy image nginx:latest command replaces a chain of Grype, detect-secrets, checkov, and kube-bench commands. The scanner runs offline-capable with a local vulnerability database, so CI pipelines avoid network round-trips to external APIs.

§03

How to use

  1. Install Trivy:
# macOS
brew install trivy

# Debian/Ubuntu
sudo apt install trivy
  1. Scan a Docker image for vulnerabilities:
trivy image nginx:latest
  1. Scan a Git repository for secrets and misconfigurations:
trivy repo https://github.com/your-org/your-repo
  1. Audit a running Kubernetes cluster:
trivy k8s --report=summary cluster
§04

Example

# Scan a project filesystem with all scanners enabled
trivy fs --scanners vuln,misconfig,secret /path/to/project

# Output as JSON for CI/CD integration
trivy image --format json --output results.json myapp:v2.1

# Fail the build if critical vulnerabilities are found
trivy image --exit-code 1 --severity CRITICAL myapp:v2.1

# Generate an SBOM in CycloneDX format
trivy image --format cyclonedx --output sbom.json myapp:v2.1
§05

Related on TokRepo

§06

Common pitfalls

  • The first scan downloads a vulnerability database (~30MB) which can timeout in air-gapped environments; pre-download with trivy image --download-db-only before going offline
  • Scanning large monorepo filesystems with all scanners enabled can be slow; use --scanners flag to limit to specific scan types
  • The --exit-code 1 flag only triggers on findings matching the specified severity; omitting --severity means any finding fails the build

Frequently Asked Questions

What types of targets can Trivy scan?+

Trivy scans container images, local filesystems, Git repositories, Kubernetes clusters, and cloud infrastructure (AWS, GCP, Azure). Each target type supports the full range of scanners: vulnerabilities, misconfigurations, secrets, and SBOM generation.

How does Trivy compare to Grype or Snyk?+

Grype focuses solely on vulnerability scanning for container images. Snyk is a commercial platform covering vulnerabilities and IaC. Trivy covers vulnerabilities, misconfigurations, secrets, and SBOM in a single open-source binary, making it broader in scope than Grype and free unlike Snyk.

Can Trivy run in CI/CD pipelines?+

Yes. Trivy provides JSON, SARIF, and table output formats. The --exit-code flag lets you fail builds on findings. Official GitHub Actions, GitLab CI templates, and Jenkins plugins are available. The scanner runs as a single binary with no daemon or server dependency.

Does Trivy work offline?+

Trivy can work offline after the initial vulnerability database download. Run 'trivy image --download-db-only' to cache the database, then use '--skip-db-update' for subsequent scans. This is useful for air-gapped environments.

What secret types does Trivy detect?+

Trivy detects API keys, passwords, tokens, private keys, and other credentials embedded in source code, Dockerfiles, and container image layers. It uses pattern matching and entropy analysis to minimize false positives.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets