← All articles

Docker Security Scanning: Find Vulnerable Images Before You Ship

Docker security scanning is the practice of inspecting a container image's layers, OS packages and application dependencies against known-vulnerability databases before that image ships to production. Run it at build time, in CI, and on a schedule against images already in your registry — because a clean scan on Monday doesn't mean the image is clean on Friday, when a new CVE lands against a package you never touched. Teams that skip this step aren't taking a small risk: industry data shows most container images in the wild are carrying exploitable flaws today.

That risk is bigger than most teams assume. Sysdig's Cloud-Native Security and Usage Report found that 87% of container images contain high or critical severity vulnerabilities, and a separate Sysdig analysis put the share of production workloads running patchable high-or-greater severity vulnerabilities at 86%. Chainguard's 2024 research found the average "official" Docker Hub image ships with roughly 328 known vulnerabilities, 12% of them critical or high — numbers that hold up because container images bundle an entire OS userland plus your application dependencies, and most of that surface area has nothing to do with the code your team actually wrote.

Why Docker images accumulate vulnerabilities

A container image is a stack of layers, and most of what's in a typical FROM ubuntu or FROM debian image is OS packages your application never calls: shells, compilers, package managers, locale data, long-abandoned libraries. Every one of those packages carries its own CVE history. Pull a base image once, and you inherit everything wrong with it on day one; never rebuild it, and you inherit every CVE disclosed against it afterward too, even though your Dockerfile hasn't changed.

This is distinct from scanning your running infrastructure or cloud accounts for misconfigurations — see our broader cloud vulnerability scanner guide for that side of the problem — because Docker security scanning operates on the artifact itself, before a single container runs. It's also narrower than general container runtime security: this post is about catching the vulnerable image at build time, not about seccomp profiles, admission controllers or the Kubernetes layer.

What a Docker image scanner actually checks

A container image scanner unpacks each layer and matches installed packages against vulnerability feeds — typically the National Vulnerability Database, GitHub Security Advisories, OS-specific trackers (Alpine SecDB, Debian Security Tracker, RHEL errata), and increasingly CISA's Known Exploited Vulnerabilities list and EPSS exploit-probability scores to help with prioritization. A useful scan returns, per finding:

  • the vulnerable package and installed version
  • the CVE ID and severity
  • whether a fixed version exists, and which one
  • which layer introduced it
ToolLicense / costWhat it scansWhere it fits
Trivy (Aqua Security)Open source, Apache 2.0OS packages, language deps, IaC, secrets, licensesOne free scanner for images, filesystems and IaC; default scanner for GitLab Container Scanning
Grype + Syft (Anchore)Open sourceOS and language-specific packages, from SBOMsSBOM-first pipelines; pairs with Syft for inventory
Docker ScoutFree for 1 repo (Personal); unlimited from Team ($15/user/month billed annually)OS and app deps, policy evaluation, remediation suggestionsTeams already standardized on Docker Hub/Desktop
Registry-native scanning (ECR, Artifact Registry, ACR)Billed by cloud providerOS and app deps, on pushA backstop that runs regardless of what your CI does

Trivy downloads its vulnerability database and refreshes it roughly every six hours, so results reflect current advisories, not whatever was known when the image was built. A typical run looks like:

docker run --rm aquasec/trivy image --severity HIGH,CRITICAL nginx:alpine

Grype runs entirely locally against a container image, directory, or SBOM, with no external service call required:

grype alpine:latest

Both tools are free and open source and are reasonable defaults for most teams; Docker Scout adds policy enforcement, auto-remediation suggestions, and health scoring but gates unlimited scanned repositories behind a paid Team or Business plan. None of these tools replace a human-verified pentest — they tell you a known CVE exists in a package, not whether it's actually reachable and exploitable in your specific application context, which is the gap security testing in your CI/CD pipeline and dynamic testing exist to close.

Reading scan output without drowning in CVEs

A fresh scan of a bloated base image can return hundreds of findings, most of them low-severity noise in packages you never execute. Work through results in this order:

  1. Filter to HIGH and CRITICAL first. Both Trivy and Grype support severity flags; don't try to triage everything at once.
  2. Check for a fixed version. If a fix exists and bumping the package resolves it, that's a same-day change. If no fix exists yet, you need a compensating control or risk acceptance.
  3. Check reachability. A critical CVE in a library your code never imports or calls is lower priority than a medium-severity flaw in something on your actual request path. Grype's EPSS and KEV signals help here by surfacing what's actually being exploited in the wild, not just what scores high on CVSS.
  4. Trace it to a layer. Most tools show which RUN or FROM instruction introduced a package, so you fix the Dockerfile line, not just the symptom.

Dockerfile practices that reduce your scan surface

The fastest way to shrink your vulnerability count isn't a better scanner — it's shipping a smaller image. A few concrete changes:

  • Pin and minimize your base image. alpine and distroless images carry a fraction of the CVEs of general-purpose ubuntu or debian bases — one comparison found Alpine 3.19 at roughly 0–5 average CVEs versus 180+ for Ubuntu 22.04 and 250+ for Debian Bookworm, with Google Distroless images at 0–3.
  • Use multi-stage builds. Compile or install dependencies in a build stage, then copy only the finished artifact into a minimal runtime stage with no compiler, package manager or shell. The OWASP DevSecOps Guideline's container hardening reference and the OWASP Node.js Docker Cheat Sheet both walk through this pattern in detail.
  • Run as a non-root user. Add a USER instruction so the container process doesn't run as root. This is CIS Docker Benchmark control 4.1 and the OWASP Docker Security Cheat Sheet calls it "the best way to prevent privilege escalation attacks."
  • Never bake secrets into layers. Credentials passed via ARG, ENV, or COPY followed by a later rm still persist in image history and cache layers. Use build secrets (RUN --mount=type=secret) and a .dockerignore instead.
  • Rebuild on a schedule, not just on code change. An image that hasn't been rebuilt in three months is scanning against three-month-old packages even if your application code is untouched.

Where Docker scanning fits in CI/CD

Image scanning belongs at two points: a blocking gate in the build pipeline (fail the build on new HIGH/CRITICAL findings above an agreed threshold), and a recurring scan against everything already deployed, since new CVEs are disclosed against old images constantly. Grype and Trivy both support CI failure thresholds out of the box, and most registries (ECR, Artifact Registry, ACR) scan on push as a backstop regardless of what your pipeline does.

Dockerfiles and image scans don't cover your Terraform, CloudFormation or Kubernetes manifests — misconfigured infrastructure defined as code is a separate, equally common source of breaches. SecurityInfinity's infra-as-code audit checks those definitions for the kind of exposure that a clean image scan won't catch, and our image security scanner extends automated image and dependency checks into the broader autonomous recon the platform runs against your verified assets. For teams building this into a wider pipeline strategy, infrastructure as code security scanning and our rundown of open-source automated penetration testing tools are useful next reads — the latter covers where free scanners like Trivy and Grype stop being sufficient on their own.

Where automated scanning stops

CVE scanners tell you a vulnerable package exists. They don't tell you whether an attacker can reach your app through it, chain it with a misconfigured API endpoint, or pivot from a compromised container into your cloud environment. That's the gap between dependency scanning and an actual penetration test: a scanner flags the door; a pentest checks whether it opens. If you need a report that maps findings to real exploitability and ships with engineer-verified evidence rather than a raw CVE list, a startup pentest extends past image scanning into authenticated, business-logic and privilege-escalation testing — the kind enterprise security questionnaires and SOC 2 auditors actually ask for.

Frequently asked questions

What is Docker security scanning?

It's the process of checking a container image's OS packages and application dependencies against known-vulnerability databases (NVD, GitHub Advisories, OS trackers) before and after deployment. It identifies CVEs by package and version, typically flags whether a fix is available, and should run both in CI and on a recurring schedule against images already deployed.

Is Docker Scout free?

Partly. Docker's free Personal plan includes continuous vulnerability analysis for one repository; Pro extends that to two. Unlimited Scout-enabled repositories require a paid Team ($15/user/month billed annually) or Business plan. On-demand CLI scans work on any plan regardless of repository limits.

Trivy vs. Grype: which should I use?

Both are free, open source, and run entirely locally without a required external service. Trivy additionally scans infrastructure-as-code files and secrets in the same pass, which makes it a good single tool if you want one scanner for images and IaC together. Grype pairs naturally with Syft for SBOM-first workflows and adds EPSS/KEV-based risk prioritization on top of raw CVSS severity. Many teams run both and compare results, since no single vulnerability database has full coverage.

Why does my Docker image have so many vulnerabilities even though I didn't write that code?

Most of a typical image is OS userland your base image pulled in — a shell, package manager, compiler toolchain, and system libraries you never call directly. Research has found official Docker Hub images average roughly 328 known vulnerabilities, nearly all inherited from the base image rather than introduced by application code. Switching to a minimal or distroless base and rebuilding on a schedule addresses most of this.

Does scanning Docker images satisfy SOC 2 or ISO 27001 requirements?

Vulnerability scanning supports those frameworks' continuous monitoring and vulnerability management controls, but it isn't a substitute for the penetration testing most SOC 2 Type II audits and ISO 27001 Annex A reviews expect. Image scans catch known CVEs in packages; auditors and enterprise customers typically also want evidence of exploitability testing against your actual application, which is what a dedicated pentest report and attestation letter provide.

Start with our infra-as-code audit or image security scanner on a verified domain, or go straight to a startup pentest if you need a report an auditor or enterprise customer will accept.

Find what attackers can see, before they do.

AI pentesting agents test your web app, API and cloud, and every finding comes with evidence and a fix. First report in about 10 minutes.

Stay ahead of attackers.

New vulnerabilities, breach write-ups and practical fixes. A few emails a month.