Skip to content

Trivy

Install Trivy and scan project files, Git repositories, container images and Kubernetes workloads for vulnerabilities and misconfigurations.

2 min readUpdated

Trivy is an open-source security scanner from Aqua Security. It finds known vulnerabilities in dependencies and operating system packages, misconfigurations in Dockerfiles, Kubernetes manifests and Terraform (Infrastructure as Code), and secrets committed by mistake. It scans a local directory, a remote Git repository, a container image or a running Kubernetes cluster.

Install Trivy

On macOS (and Linux with Homebrew):

Terminal window
brew install trivy

The Trivy documentation lists packages for Debian, Ubuntu, RHEL and others, and a container image.

The first time Trivy runs, it downloads the vulnerability database and creates a cache directory. Remove the cache and the databases with:

Terminal window
trivy clean --all

Older Trivy versions used trivy --reset for this.

Scan a project directory

Scan the dependencies of the project in the current directory. Trivy detects lock files and manifests such as Gemfile.lock, package-lock.json or pom.xml and looks up each dependency in its database:

Terminal window
trivy fs .

By default trivy fs looks for vulnerabilities and secrets. Add misconfiguration checks with --scanners; the scan then includes any Dockerfiles, Kubernetes manifests and Terraform files in the directory:

Terminal window
trivy fs --scanners vuln,misconfig .

The flag was called --security-checks vuln,config in older versions.

Scan a remote repository

Scan a Git repository without cloning it first:

Terminal window
trivy repo https://github.com/<owner>/<repository>

Scan container images

Scan an image for vulnerabilities in its operating system packages and application dependencies:

Terminal window
trivy image my-test-image:version

Show only the findings that need action with --severity:

Terminal window
trivy image --severity HIGH,CRITICAL my-test-image:version
trivy image --severity HIGH,CRITICAL docker_username/my-test-images:version

The second form scans an image from a registry; Trivy pulls it if it is not available locally.

Scan Kubernetes

Scan a cluster with trivy k8s

Current Trivy versions scan a cluster directly. The command uses the current context from your kube configuration:

Terminal window
trivy k8s --report summary

Limit the scan to a namespace with --include-namespaces kube-system, or pass a context name as an argument.

Scan one workload with the kubectl plugin

The kubectl plugin scans the images used by a single Kubernetes resource, such as a pod or a deployment. Install it once:

Terminal window
trivy plugin install github.com/aquasecurity/trivy-plugin-kubectl

Then scan a pod or a deployment:

Terminal window
trivy kubectl pod mypod
trivy kubectl deployment mydeployment -n mynamespace

Pass Trivy options after --, for example trivy kubectl job myjob -n mynamespace -- --severity CRITICAL. The plugin has not changed since 2024; prefer trivy k8s for new setups.

References

Related notes

4 min readTürkçe

Ollama

GPU'suz, yalnız CPU ile çalışan makinelerde Ollama ile yerel LLM çalıştırma ve hızı belirleyen ayarlar.

  • AI & Data
  • DevOps & Containers
7 min readTürkçe

Podman

Podman kurulumu, rootless container'ları systemd ve Quadlet ile kullanıcı servisi olarak çalıştırma ve sık görülen hatalar.

  • DevOps & Containers
4 min read

Kubernetes

Run containers and local Kubernetes on macOS with Podman, Podman Desktop, kubectl and minikube, and describe workloads in Kubernetes YAML.

  • DevOps & Containers

Type to search the whole site.