What Is Container Security Scanning? Trivy, Grype & Best Practices

Written by: Vilas Varghese
14 Min Read
Summarise in seconds:

Container security scanning is the automated process of inspecting container images, configuration files, and running containers to detect known vulnerabilities, exposed secrets, and misconfigurations before they reach production. It works by comparing every OS package and application dependency inside an image against vulnerability databases such as the National Vulnerability Database (NVD), then flagging anything with a published CVE.
Two of the most widely used open-source tools for this are Trivy and Grype. Trivy, built by Aqua Security, is an all-in-one scanner that checks container images, filesystems, Kubernetes clusters, and infrastructure-as-code files for vulnerabilities, secrets, and misconfigurations from a single binary. Grype, built by Anchore, focuses specifically on vulnerability matching and pairs with Syft to generate a software bill of materials (SBOM) before scanning it.
Best practices for container security scanning include shifting scanning left into the CI/CD pipeline, using minimal or distroless base images, running containers as non-root, and rescanning images continuously in the registry, since new CVEs are published daily even against images that were clean at build time. 

What Is Container Security Scanning?

Container security scanning is the automated inspection of container images, their dependencies, and running workloads to detect known vulnerabilities, hardcoded secrets, and misconfigurations before they reach production. A scanner unpacks every layer of an image, matches each OS package and application library against public vulnerability databases such as the NVD, and flags anything with a published CVE.

Containers ship applications with their own OS libraries baked in, so a single base image, say a Python or Node.js image pulled from a public registry, can carry dozens of outdated packages the development team never wrote or reviewed. Container security scanning exists specifically to catch that inherited risk before an image reaches production.

Scaler Carousel

Why Container Security Scanning Matters in 2026

Container adoption has moved past early experimentation, and most teams now ship several image builds a day, each pulling in a fresh set of dependencies. Recent industry scans found that a large majority of production container images carry at least one high-severity vulnerability. Attacks on build pipelines, unverified registry pulls, and misconfigured Kubernetes deployments have also picked up, so a weak spot in one image can now spread across an entire pipeline instead of staying isolated.

For engineers, this has turned container security scanning from a nice-to-have into a core CI/CD skill. DevOps and platform teams are increasingly expected to own scanning gates, not just write Dockerfiles- the hands-on fluency that separates a working DevOps engineer from someone who has only studied the theory.

How Does Container Security Scanning Work?

Effective container security scanning is not a single checkpoint; it runs at multiple lifecycle stages:

StageWhat Gets CheckedTypical Tools
BuildDockerfile syntax, base image CVEs, hardcoded secretsTrivy, Grype, Hadolint
RegistryContinuous rescans of stored images as new CVEs are publishedTrivy, Harbor, registry-native scanners
CI/CD gatePipeline blocks or flags builds above a severity thresholdTrivy, Grype (exit codes + SARIF)
RuntimeLive containers monitored for anomalous process or file behaviorFalco, runtime agents

Most scanning tools, including Trivy and Grype, operate at the build and registry layers, inspecting image contents statically without needing the container to be running. Runtime protection is a separate discipline that watches live processes and network calls, and it sits alongside, not instead of, scanning.

What Is Trivy?

Trivy is a free, open-source security scanner built by Aqua Security. It ships as a single Go binary with no server setup required, and it can scan container images, filesystems, git repositories, VM images, Kubernetes clusters, and IaC files such as Terraform, CloudFormation, and Helm charts, all from one tool. Trivy also generates SBOM output in CycloneDX and SPDX formats.

With more than 36,000 GitHub stars, Trivy is the default scanner behind projects like Harbor and a widely used option inside GitHub, GitLab, and Jenkins pipelines.

Key Trivy Features

  • Scans OS packages (Alpine, Debian, Ubuntu, RHEL, Amazon Linux) and language dependencies (npm, pip, Maven, Go modules, Cargo)
  • Detects hardcoded secrets, exposed API keys, and license issues in the same pass
  • Absorbed the former tfsec project, adding Terraform and IaC misconfiguration checks
  • Ships trivy-operator for continuous scanning inside Kubernetes clusters
  • Auto-updates its vulnerability database roughly every 12 hours

Running a Trivy Scan

A basic trivy scan needs a single command:

trivy image nginx:1.27

To gate a CI/CD pipeline so it only fails the build on serious findings:

trivy image –severity HIGH,CRITICAL –exit-code 1 myapp:latest

What Is Grype?

Grype is Anchore’s open-source vulnerability scanner. Unlike Trivy’s broad scope, Grype does one job: matching packages inside a container image or filesystem against known CVEs, using direct, CPE-based, and indirect dependency matching to keep false positives low.

Grype pairs with Syft, Anchore’s companion SBOM generator. A common workflow is to generate an SBOM once with Syft and rescan it with Grype whenever a new CVE is published, without rebuilding or re-pulling the image.

Key Grype Features

•  Deep package-to-CVE matching tuned for a low false-positive rate

•  SBOM-first workflow through Syft (CycloneDX, SPDX, in-toto attestation support)

•  Outputs SARIF for GitHub and GitLab code scanning, with severity-based exit codes for build gating

•  Stays focused on vulnerabilities only, no IaC, secrets, or Kubernetes-cluster scanning

Running a Grype Scan


grype myapp: latest

To generate an SBOM first and scan it separately:
syft myapp:latest -o cyclonedx-json | grype

Trivy vs Grype: Which Should You Use?

CapabilityTrivyGrype
Vulnerability scanningYesYes
IaC misconfiguration scanningYes (Terraform, CloudFormation, Helm)No
Secrets scanningYesNo
Kubernetes-native scanningYes (trivy-operator)No
SBOM generationBuilt-inVia Syft
Best fitOne binary for vulnerabilities, IaC, secrets & KubernetesSBOM-first pipelines or a focused second opinion

For most teams, Trivy is the simpler starting point since it covers more ground with one install and one config file. Grype earns its place in an SBOM-first pipeline or as a second scanner: since the two pull from different vulnerability databases, running both on critical images catches edge cases either tool alone can miss.

Container Security Scanning Best Practices

  • Shift scanning left. Run a trivy scan or Grype check on every pull request, not just before a production release, so a vulnerable base image never gets merged.
  • Inspect every layer. Scanners should check the full image, not only the top writable layer, since secrets and vulnerable packages are frequently baked into earlier build layers.
  • Choose minimal base images. Distroless or Alpine-based images carry fewer packages, shrinking what a scanner, and an attacker, has to work with.
  • Run as non-root. Avoid privileged containers and drop unnecessary Linux capabilities so a compromised container can’t easily escalate.
  • Track an SBOM per image. A software bill of materials lets you instantly check whether a newly disclosed CVE affects anything already running.
  • Rescan continuously in the registry. An image that was clean at build time can become vulnerable the moment a new CVE is published.
  • Gate builds by severity, not zero tolerance. Failing CI on every LOW finding trains teams to ignore scan output; gate on HIGH/CRITICAL and triage the rest separately.
  • Pin your tooling. Pin scanner versions and third-party GitHub Actions to a commit SHA, this alone would have limited the 2026 Trivy Action supply-chain incident.
  • Benchmark configuration against CIS. Use the CIS Docker and Kubernetes Benchmarks alongside scanning to catch configuration issues scanners sometimes miss.

Common Container Security Issues Scanners Catch

Across most codebases, the same handful of container security issues show up repeatedly:

  • Outdated OS packages and unpatched base images
  • Hardcoded secrets, tokens, or API keys baked into image layers
  • Vulnerable application dependencies across npm, pip, Maven, and Go modules
  • Containers running in privileged mode or as root by default
  • Exposed ports and unnecessary services left enabled in the Dockerfile
  • Missing or incomplete SBOMs, which slow down response when a new CVE hits a component already in production

Free Courses by top Scaler instructors

Choosing the Right Container Security Tools for Your Pipeline

There’s no single “best” scanner, it depends on how your pipeline is already built. Teams that want one tool covering vulnerabilities, IaC, secrets, and Kubernetes usually start with Trivy. Teams already invested in Syft for SBOMs lean toward Grype. Regulated environments often run both, since independent databases widen coverage. Most container security tools stop at build and registry, so pair them with a runtime layer, such as Falco, for live threat detection.

CTA: Ready to Master DevSecOps and Cloud Infrastructure?

Scaler’s DevOps, Cloud & AI Platform Engineering Program covers Docker hardening, Kubernetes security, CI/CD, Terraform, and cloud infrastructure through hands-on projects and 1:1 mentorship.

Explore the Program

Build a Career Securing Cloud-Native Infrastructure

Container security scanning sits at the intersection of DevOps and security, and it’s increasingly a line item in DevOps and platform engineering job descriptions, not a separate security-team task. Engineers who can set up a Trivy scan inside a pipeline, read a Grype report, and turn findings into a fix are more employable across cloud, DevOps, and SRE roles. If you’re looking to build production-grade DevOps and container security skills with mentorship and real pipeline projects, Scaler’s DevOps, Cloud and AI Platform Engineering program can help you get there faster than learning it alone.

Conclusion

Container security scanning has gone from an optional CI/CD step to a baseline expectation for any team shipping containers to production. Trivy and Grype cover the two most common approaches, all-in-one versus focused, SBOM-first, and teams get the strongest coverage by pairing scanning with the best practices above, rather than treating either tool as a finished solution.

Scaler’s DevOps, Cloud & AI Platform Engineering Program covers Docker, Kubernetes, CI/CD, Terraform, and cloud security hands-on, with production-focused projects and 1:1 mentorship.

Explore the Program 

Frequently Asked Questions

What is container security scanning?

Container security scanning is the automated process of checking container images and running containers for vulnerabilities, secrets, and misconfigurations before and after deployment.

Is Trivy free to use?

Yes. Trivy is a free, open-source scanner from Aqua Security; you only pay if you use Aqua’s commercial platform for enterprise features.

How do I run a trivy scan on a Docker image?

Run trivy image <image-name> from the CLI. Add –severity HIGH,CRITICAL –exit-code 1 to fail CI builds only on serious findings.

What is the difference between Trivy and Grype?

Trivy is an all-in-one scanner covering vulnerabilities, IaC, secrets, and Kubernetes, while Grype focuses only on vulnerability matching and pairs with Syft for SBOMs.

What container security issues do scanners typically catch?

Scanners commonly catch outdated OS packages, hardcoded secrets, vulnerable dependencies, and privileged containers.

What are the best container security tools for a CI/CD pipeline?

Trivy and Grype are the two most widely adopted open-source container security tools; many teams run both for broader CVE coverage.

Is container security scanning enough to secure containers in production?

No. Scanning catches known vulnerabilities before deployment; you still need runtime monitoring and least-privilege configs for full container security.

Share This Article
Follow:
Vilas Varghese is a DevOps expert, corporate trainer, and technology educator with extensive experience in cloud computing, Docker, Kubernetes, CI/CD, infrastructure automation, and AI-native DevOps. He has trained thousands of software professionals and engineering teams, helping them build practical, production-ready skills for modern cloud environments. At Scaler, Vilas contributes technical content that simplifies complex DevOps concepts into actionable learning for aspiring and experienced engineers alike.
Leave a comment

Get Free Career Counselling