🔒
Monitoring & Observability

Trivy

Comprehensive security scanner for containers and IaC

🐧 Linux🍎 Mac🪟 Windows
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

What is this?

Trivy scans containers and code for known security vulnerabilities.

📥

Step 01

Install Trivy

(01)Install Trivy

Linux
1# Ubuntu / Debian
2sudo apt-get install wget apt-transport-https gnupg lsb-release
3wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
4echo "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.list
5sudo apt-get update
6sudo apt-get install trivy
7
8# Or direct install
9curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin

Step 02

Verify Installation

(01)Check Version

Linux
1trivy --version

Step 03

Scan with Trivy

(01)Scan Container Images

Linux
1# Scan image for vulnerabilities
2trivy image nginx:latest
3
4# Scan with severity filter
5trivy image --severity HIGH,CRITICAL nginx:latest
6
7# Output as JSON
8trivy image -f json -o results.json nginx:latest

(02)Scan Filesystem & IaC

Linux
1# Scan local filesystem
2trivy fs .
3
4# Scan Terraform
5trivy config ./terraform/
6
7# Scan Kubernetes manifests
8trivy config ./k8s/

(03)Update Database

Linux
1trivy image --download-db-only