liveBook · Manning

Trivy

As explained in Learn Docker in a Month of Lunches, Second Edition

Trivy is an open-source security scanner for container images, source repositories, dependencies, and infrastructure configuration.

Trivy is an open-source security scanner for Docker images, repositories, and configuration. It fits naturally into golden-image builds and CI/CD workflows, where vulnerability databases can be cached between scans. section 17.2

A practical scan workflow can:

  • Scan an image for vulnerabilities, then narrow results to HIGH and CRITICAL severity. section 17.2
  • Use an ignore file for accepted vulnerabilities after evaluating their operational risk. section 17.2
  • Scan remote Git repositories for vulnerabilities or misconfigured Dockerfiles and Kubernetes manifests. section 17.2

Scan an image

Create a trivy-cache volume, then run diamol/trivy:2e image --scanners vuln against diamol/openjdk:2e. Repeat with --severity HIGH,CRITICAL and optionally --ignorefile /sample.trivyignore. section 17.2

# create a volume to use as a data cache:
docker volume create trivy-cache
# run a vulnerability scan on the book's OpenJDK image:
docker run -v trivy-cache:/root/.cache `
 -it diamol/trivy:2e image --scanners vuln diamol/openjdk:2e
# run the same scan but ignore low severity problems:
docker run -v trivy-cache:/root/.cache `
 -it diamol/trivy:2e image --scanners vuln `
 --severity HIGH,CRITICAL diamol/openjdk:2e
# and finally ignore specific problems we have accepted:
docker run -v trivy-cache:/root/.cache `
 -it diamol/trivy:2e image --scanners vuln `
 --severity HIGH,CRITICAL --ignorefile /sample.trivyignore `
 diamol/openjdk:2e

Runnable commands demonstrate cached image scans, severity filtering, and accepted-vulnerability exclusions. section 17.2

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Demonstrates runnable image, repository, and misconfiguration scans, but defers broader security analysis.
Examples
Uses OpenJDK image scans, remote Git repository scans, severity filters, cached databases, and ignore files.
What it assumes
Uses Docker commands, image names, repository URLs, and basic vulnerability-severity concepts.
What you can do after
Operate Trivy through Docker commands to scan artifacts, filter findings, and record accepted vulnerabilities.
How it connects
Connects base images, Docker images, CI/CD, vulnerability databases, Dockerfiles, and Kubernetes manifests.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.