Nexus Void Research

Docker, Container Security, Container Image Scanning, Trivy, Grype, Docker Scout, Base Images, How-to

How to Scan Docker Images for Vulnerabilities (and Fix Them)

How to scan Docker images for vulnerabilities with Trivy, Grype or Docker Scout, read the results, fix base image CVEs and automate it in CI.

To scan Docker images for vulnerabilities, run an image scanner such as Trivy, Grype or Docker Scout against the image (trivy image myapp:latest), which lists known CVEs in the OS packages and application libraries inside every layer. Then fix by rebuilding on a patched or smaller base image, upgrading the affected packages, and adding the scan to CI so images with fixable critical CVEs fail the build.

A container image bundles your code with an operating system and hundreds of packages you did not write. Most of the CVEs in a typical image come from the base image, not your application. The NIST Application Container Security Guide (SP 800-190) lists image vulnerabilities as the first image risk for exactly that reason. This guide covers scanning locally, reading the results, fixing them and automating the check.

What does a container image scanner check?

An image scanner unpacks each layer, builds an inventory of what is installed, and matches it against vulnerability databases. It looks at:

  • OS packages installed by the base image and your RUN apt-get or apk add lines (Debian, Ubuntu, Alpine, Red Hat and others).

  • Application dependencies baked into the image: npm, pip, Go modules, Java JARs, Ruby gems and more.

  • Layer attribution, so you can tell whether a CVE came from the base image or a line in your Dockerfile.

Most scanners can also check the Dockerfile itself for misconfigurations, such as running as root or using latest tags, and look for secrets left in layers.

Step 1: Scan an image locally

All three common scanners are free to use and scan a local image or one pulled from a registry.

Trivy

trivy image myapp:latest
trivy image --severity HIGH,CRITICAL --ignore-unfixed myapp:latest
trivy image myapp:latest
trivy image --severity HIGH,CRITICAL --ignore-unfixed myapp:latest
trivy image myapp:latest
trivy image --severity HIGH,CRITICAL --ignore-unfixed myapp:latest

Grype

grype myapp:latest
grype myapp:latest --only-fixed --fail-on high
grype myapp:latest
grype myapp:latest --only-fixed --fail-on high
grype myapp:latest
grype myapp:latest --only-fixed --fail-on high

Docker Scout (built into recent Docker Desktop and CLI)

docker scout quickview myapp:latest
docker scout cves myapp:latest
docker scout recommendations myapp:latest
docker scout quickview myapp:latest
docker scout cves myapp:latest
docker scout recommendations myapp:latest
docker scout quickview myapp:latest
docker scout cves myapp:latest
docker scout recommendations myapp:latest

--ignore-unfixed and --only-fixed hide CVEs that have no patched package yet. Those are worth tracking, but you cannot fix them by upgrading, so hiding them makes the first report actionable.

Step 2: Read the results

A scanner row usually shows the package, installed version, fixed version, CVE ID, severity and the layer or file it came from. Before fixing anything, split the report into three groups:

Group

How to spot it

Typical fix

Base image CVEs

Layer is the FROM image; package is an OS library

Change or update the base image

Your OS packages

Layer is one of your RUN apt-get install lines

Upgrade or remove the package

Application dependencies

Path points to node_modules, site-packages, a JAR

Upgrade in your lockfile and rebuild

On most images the first group is by far the largest, which is good news: one base image change can clear most of the report.

Step 3: Prioritize what to fix first

Severity alone over-states urgency. Sort the fixable findings by:

  1. Known exploitation: is the CVE in the CISA Known Exploited Vulnerabilities catalog?

  2. Exploit likelihood: a high EPSS score.

  3. Exposure: does the container accept traffic from the internet?

  4. Use: does your application actually run the vulnerable component? A vulnerable library in an unused OS package matters less than one in your web server.

Our 2026 vulnerability statistics show why: over half of scored CVEs are High or Critical, but only 0.44% are confirmed exploited.

Step 4: Fix by changing the base image

The fixes that clear the most CVEs, in order:

  • Rebuild on the latest patch of your base image. Base images are republished with security updates; rebuilding with docker build --pull picks them up.

  • Switch to a smaller base. -slim variants, Alpine or distroless images contain far fewer packages, so far fewer CVEs. Test carefully: Alpine uses musl rather than glibc, which can change behaviour.

  • Use multi-stage builds so compilers, package managers and build tools stay in the build stage and never ship in the final image.

  • Pin by digest (FROM node:22-slim@sha256:...) so builds are reproducible, and update the digest on a schedule rather than drifting on a tag.

FROM node:22 AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:22-slim
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
USER node
CMD ["node", "dist/server.js"]
FROM node:22 AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:22-slim
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
USER node
CMD ["node", "dist/server.js"]
FROM node:22 AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:22-slim
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
USER node
CMD ["node", "dist/server.js"]

Step 5: Fix the remaining packages

  • OS packages you installed: upgrade them in the same RUN line, and remove anything the runtime does not need. Clean package caches in the same layer.

  • Application dependencies: upgrade them in your lockfile, not inside the image, and rebuild. See how to fix npm audit vulnerabilities for Node.js projects.

  • No fix available: record the CVE, check whether the vulnerable code path is used, and set a reminder to rescan. Do not let unfixable CVEs block every build.

Step 6: Scan in CI and on a schedule

Images go stale. An image that scanned clean last month can have new CVEs today without a single code change, because new advisories are published every day.

  • Scan in CI on every build and fail on fixable High and Critical findings. With Trivy: trivy image --exit-code 1 --severity HIGH,CRITICAL --ignore-unfixed myapp:$TAG.

  • Rescan running images on a schedule, daily or weekly, and rebuild when new fixes appear.

  • Scan the Dockerfile for misconfigurations too (trivy config .), and follow the CIS Docker Benchmark for host and runtime hardening.

  • Keep an SBOM per image so that when the next big CVE lands you can answer "are we affected?" in minutes. See our SBOM guide for startups.

How does ARGUS scan container images?

ARGUS scans the base images your repositories use as part of every repository scan, so you do not need a separate container tool or access to your Docker daemon.

  1. It finds your Dockerfiles in the repository and reads each FROM line.

  2. It scans each base image directly from the registry, with no local build, covering OS and application packages with layer attribution.

  3. It reports only CVEs with an available fix, as findings against the Dockerfile, so every container finding is something you can act on by rebuilding on a newer base.

  4. It keeps container findings separate from your own code and your dependencies, so a long base-image list does not hide the bugs only your team can fix.

  5. It ranks everything by exploitability, with one 0 to 100 priority score that blends CVSS, EPSS, CISA KEV and reachability, and builds an SBOM and an infrastructure bill of materials that includes your base images.

Limits: ARGUS scans up to 3 distinct base images per repository and skips scratch, local multi-stage references and images set through build arguments. It scans the base images named in your Dockerfiles, not the final images you build and push. Read more about ARGUS SCA and ARGUS SBOM, or scan a repository free.

Frequently asked questions

How do I scan a Docker image for vulnerabilities?

Install an image scanner such as Trivy, Grype or Docker Scout and run it against the image, for example trivy image myapp:latest. It lists known CVEs in OS packages and application dependencies with the installed and fixed versions. Add --ignore-unfixed to see only the CVEs you can fix now.

How do I scan a Docker image locally?

Scanners like Trivy and Grype read images from your local Docker daemon, so build the image and run trivy image <name>:<tag> or grype <name>:<tag> on the same machine. Docker Desktop users can also run docker scout cves <image>. No registry push is needed.

How do I fix vulnerabilities in a Docker image?

Rebuild on the latest patch of your base image with docker build --pull, switch to a slimmer or distroless base, use multi-stage builds so build tools do not ship, upgrade remaining OS packages, and upgrade application dependencies in your lockfile before rebuilding. Then rescan to confirm.

Why does my Docker image have so many vulnerabilities?

Most come from the base image, which ships an operating system with hundreds of packages your application may never use. Full OS images like ubuntu or node carry far more CVEs than -slim, Alpine or distroless variants. Many findings also have no fix yet; filter them with --ignore-unfixed.

What is the best free Docker image vulnerability scanner?

Trivy, Grype and Docker Scout are widely used and free for local scanning. Trivy also scans Dockerfiles, Kubernetes manifests and Terraform. Grype pairs with Syft for SBOMs. Docker Scout is built into Docker Desktop. Pick one that fits your CI and run it on every build.

Should I fail the build on image vulnerabilities?

Yes, for fixable High and Critical findings, using a flag such as --exit-code 1 --severity HIGH,CRITICAL --ignore-unfixed. Failing on unfixable or low-severity findings blocks every build without improving security, so teams start ignoring the check. Track those separately.

How often should I scan Docker images?

On every build in CI, and again on a schedule for images already running, because new CVEs are published daily. An image that scanned clean last month can have new critical findings today without any code change. Rebuild when a fix becomes available.

Are distroless or Alpine images more secure?

They usually have far fewer CVEs because they contain far fewer packages, and distroless images have no shell or package manager for an attacker to use. Alpine uses musl instead of glibc, which can change application behaviour, so test before switching.

DATA SOURCES

NIST SP 800-190: https://csrc.nist.gov/pubs/sp/800/190/final ; CIS Docker Benchmark: https://www.cisecurity.org/benchmark/docker ; CISA KEV ; FIRST EPSS

Liked this post? Share it: