Container images package applications and their dependencies into artifacts that can be distributed and deployed across different environments. However, an image may also contain outdated operating system packages, vulnerable libraries, exposed secrets, or other security concerns.
Scanning container images before deployment helps teams identify known vulnerabilities and investigate potential risks before an image reaches production.
Trivy is an open-source security scanner that can inspect container images and other targets for several types of security issues. This guide explains how to scan Docker images, interpret findings, export reports, and introduce container security checks into a development workflow.
Trivy is a security scanner developed by Aqua Security. Its supported targets include container images, filesystems, repositories, and infrastructure configuration, among others.
For container images, Trivy can identify known vulnerabilities in operating system packages and supported language-specific dependencies. Secret scanning is also available, while some other checks require explicit configuration.
A vulnerability finding generally indicates that a detected software component matches information in the scanner's vulnerability data. It does not automatically mean that the application is exploitable in its current environment.
The result should be reviewed alongside the affected component, available fixes, application usage, and deployment context.
Before starting, prepare:
Docker or another supported way to make the image available.
Trivy installed according to its official documentation.
Access to the container image you are authorized to assess.
Network access if the scanner needs to download vulnerability databases or image layers.
Official installation instructions are available at:
https://trivy.dev/latest/getting-started/installation/
For reproducible assessments, record the Trivy version, image reference, and scan date.
Choose an image that you own, maintain, or are authorized to evaluate.
For example, you can use a locally built application image:
docker build -t myapp:1.0 .This command builds an image from the Dockerfile in the current directory and tags it as myapp:1.0.
The example assumes that a suitable Dockerfile and application build context already exist. It does not create a working application by itself.
For production workflows, prefer a specific version tag or immutable image digest when tracking which artifact was assessed. A mutable tag may refer to different image contents at different times.
Use the following command to scan the image:
trivy image myapp:1.0Trivy examines the image and reports detected vulnerabilities based on its supported scanners and available vulnerability data.
Depending on the image, the output may include:
Package or library name.
Vulnerability identifier.
Severity.
Installed package version.
A fixed version when the data source identifies an applicable fix.
A short vulnerability description.
The first scan may take longer while the scanner downloads or updates its databases.
For a public example image, you can substitute an image from a trusted registry that you are permitted to assess. Always review the source and intended use of an image before incorporating it into a production workflow.
Large images may contain many findings. Severity filtering can help prioritize the first review.
trivy image \
--severity HIGH,CRITICAL \
myapp:1.0This command limits displayed findings to the selected severity levels.
Filtering is a prioritization mechanism, not a complete risk assessment. Lower-severity vulnerabilities may still matter, particularly when they affect sensitive components or can be combined with other weaknesses.
For a comprehensive baseline, retain a record of the full results even when the immediate review focuses on higher-severity findings.
Trivy supports structured output formats that can be archived or processed by other tools.
For example, generate a JSON report:
mkdir -p trivy-reports
trivy image \
--format json \
--output trivy-reports/myapp-report.json \
myapp:1.0The report is written to:
trivy-reports/myapp-report.jsonJSON output can support internal dashboards, audit records, and automated processing. It is not inherently a complete remediation plan; teams still need to interpret the results and assign corrective actions.
Reports may contain sensitive operational details. Store them with appropriate access controls and retention policies.
Avoid treating every reported CVE as equally urgent. A structured review should establish what the scanner found and whether the finding is relevant to the application.
Determine which package or library is associated with the vulnerability. Confirm the installed version and whether the component belongs to the operating system or the application's dependency stack.
Review the vulnerability identifier and available advisory information. Check the affected version range, relevant conditions, severity rationale, and vendor guidance.
Trivy may report a fixed version when one is known from its data sources. Confirm that the proposed update is appropriate for the package manager, operating system, and application.
An empty fixed-version field does not necessarily mean that no mitigation exists. It may reflect the available advisory information or the absence of a known fix in the data source.
A vulnerability's practical risk depends on more than its severity score. Consider whether the affected component is reachable, whether the vulnerable functionality is used, the privileges available to the process, and the consequences of exploitation.
Document the reasoning behind remediation priority and any accepted exceptions.
Vulnerable packages are only one part of container security. The way an image is built and configured can introduce additional risks.
Trivy provides configuration scanning for Dockerfiles and supported infrastructure-as-code formats.
For example, scan a directory containing a Dockerfile:
trivy config .This checks supported configuration files in the selected directory and reports applicable misconfiguration findings.
Depending on the files and rules involved, results may highlight issues such as using a mutable base-image tag or failing to configure a non-root user.
Configuration checks have their own scope and rule behavior. Review the finding descriptions before changing a build file, and test proposed changes to ensure the application continues to work correctly.
Do not assume that every configuration scanner runs by default during an image vulnerability scan. Consult the current Trivy documentation for the specific command and scanner options.
A container security check can be added to the build pipeline so that developers receive feedback before publishing or deploying an image.
The following GitHub Actions example illustrates the approach:
name: Container Image Security
on:
workflow_dispatch:
jobs:
scan:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Build image
run: docker build -t myapp:ci .
- name: Set up Trivy
uses: aquasecurity/setup-trivy@v0.2.4
with:
version: latest
- name: Scan image
run: trivy image --severity HIGH,CRITICAL myapp:ciThis is an illustrative starting point, not a verified production workflow. Before adopting it, check the official action documentation, confirm the current action versions, and pin dependencies according to your organization's supply-chain policy.
The workflow uses a manually triggered event to allow the build and scan process to be reviewed before automation is expanded.
A security scan is more useful when the team defines what happens after a finding appears.
A policy might require investigation of critical findings, block releases for confirmed high-risk issues, or allow documented exceptions with an owner and review date.
Be cautious about implementing a strict failure threshold without testing it against real project results. A threshold that generates excessive noise may encourage developers to ignore the scanner, while a permissive policy may allow serious issues to pass unnoticed.
A useful policy balances risk, remediation capacity, and the reliability of the findings.
When a relevant vulnerability is identified:
Confirm the affected package and version.
Review the vendor advisory and available fix.
Update the base image or application dependency as appropriate.
Rebuild the container image.
Scan the newly built artifact.
Record the outcome and verify that the expected finding is resolved.
Updating the Dockerfile alone does not prove that the deployed image contains the intended fix. The rebuilt image should be the artifact that is tested and promoted.
Similarly, a clean scan does not prove that an image is free of all vulnerabilities. Detection depends on scanner coverage, vulnerability data, package identification, and the image contents.
Scanning only the base image. Application dependencies added during the build may introduce separate vulnerabilities.
Using mutable tags without recording image identity. This makes it harder to reproduce an earlier scan.
Treating severity as the only priority signal. Assess application context, exposure, available fixes, and business impact.
Ignoring findings without documentation. Exceptions should have a rationale, owner, and review process.
Assuming a clean report means the image is secure. A scanner can only detect issues covered by its capabilities and available data.
Failing to rescan after rebuilding. A remediation change should be verified against the actual new artifact.
Trivy can identify known vulnerabilities in supported packages and report other configured security checks, but it does not replace every form of application security testing.
It cannot reliably prove the absence of unknown vulnerabilities, every exploitable code path, or all runtime security weaknesses.
Some packages may not be recognized, vulnerability records may be incomplete, and fix information can vary by ecosystem. Misconfiguration detection also depends on supported formats and enabled scanners.
For stronger assurance, combine image scanning with secure build practices, dependency management, secrets protection, configuration review, and runtime controls.
Trivy provides a practical way to assess container images before deployment. It can identify known vulnerabilities, produce machine-readable reports, and support repeatable checks in CI/CD workflows.
The most valuable results come from a disciplined process: scan the artifact that will actually be deployed, validate important findings, prioritize remediation using context, and rescan after rebuilding.
Container scanning is one layer of defense, not a guarantee of security. When integrated into a broader software supply-chain process, it gives teams better visibility into the risks introduced by application dependencies and image contents.
Trivy documentation: https://trivy.dev/docs/
Container image scanning: https://trivy.dev/docs/latest/guide/target/container_image/
Vulnerability scanning: https://trivy.dev/docs/latest/scanner/vulnerability/
Misconfiguration scanning: https://trivy.dev/docs/latest/scanner/misconfiguration/
Trivy GitHub repository: https://github.com/aquasecurity/trivy