Container Image Scanning with Trivy on Linux

Container image scanning on Linux using Trivy involves inspecting container layers, system libraries, and application dependencies to identify Common Vulnerabilities and Exposures (CVEs) and misconfigurations. Operating directly through the Linux CLI, continuous integration pipelines, or container runtimes, Trivy unpacks image filesystems, extracts package metadata, and cross-references that data against an updated local cache of security advisories without requiring privileged access to the host kernel.

Architecture and Workflow on Linux

Trivy operates as a standalone binary on Linux, running in user space. It handles container scanning through a sequence of discrete stages:

  1. Image Retrieval: Trivy interfaces with local Linux container storage—such as the Docker daemon (/var/run/docker.sock), containerd (/run/containerd/containerd.sock), or Podman rootless sockets—or directly pulls an Open Container Initiative (OCI) image tarball from a remote registry.
  2. Layer Extraction: Container images consist of stacked root filesystem layers. On Linux, Trivy reads these layers, decompressing tar archives sequentially in memory or a temporary directory to build the unified filesystem representation.
  3. Metadata Parsing: Trivy inspects the assembled files to identify:
    • OS Packages: Files managed by standard Linux package managers, such as dpkg status databases on Debian/Ubuntu, RPM databases on Red Hat/CentOS/Fedora, and apk databases on Alpine.
    • Language Dependencies: Manifest and lock files for application environments (e.g., package-lock.json, requirements.txt, Gemfile.lock, and Go binaries).
  4. Static Analysis: Trivy identifies hardcoded secrets, misconfigurations in embedded Dockerfiles or Kubernetes manifests, and software licenses packaged within the image.

Vulnerability Database and Matching

To evaluate detected packages, Trivy maintains a local vulnerability database on the Linux host, typically cached in ~/.cache/trivy/db/.

When a scan is initiated:

Execution Models on Linux

Trivy supports multiple implementation methods on a Linux system: