How to Scan Docker Containers for Vulnerabilities
A practical guide to scanning Docker containers for vulnerabilities — what to scan, when, and how to build it into your workflow instead of running it once.
Scanning a Docker container for vulnerabilities is a well-defined technical process, but its value depends almost entirely on when and how often it's done. A single scan at build time tells you about a moment in time; the risk that actually matters accumulates afterward.
What a Docker image scan actually checks
A container image scanner inspects the layers that make up the image and checks:
- OS-level packages in the base image against known-CVE databases
- Application dependencies bundled into the image (language-specific packages, libraries)
- Configuration issues — such as the image being configured to run as root, or containing unnecessary setuid binaries
- Embedded secrets — credentials or keys accidentally baked into a layer during the build process
Step 1: Choose where scanning happens
Scanning can occur at multiple points, and ideally happens at more than one:
- At build time, in CI, before an image is pushed to a registry — catching issues before they're deployed at all
- In the registry, scanning images already stored there, catching newly disclosed vulnerabilities in images that were clean when built
- At deploy time, as a gate before an image is allowed to run in production
- Continuously at runtime, for vulnerabilities disclosed after deployment
Build-time scanning alone is the most common setup, and it's also the most incomplete — it only reflects vulnerability data as of the moment the image was built.
Step 2: Scan every layer, not just the final image
Docker images are built in layers, and a vulnerability can be introduced in an intermediate layer even if it's not obviously present in the final application code — for example, a build tool installed temporarily and not fully removed. Effective scanning inspects the full layer history, not just the final resulting filesystem.
Step 3: Check for embedded secrets specifically
Beyond known-vulnerability scanning, check images for accidentally embedded credentials — API keys or connection strings sometimes get baked into an image during a build step, especially if secrets are passed as build arguments rather than injected at runtime.
Step 4: Validate configuration, not just package versions
A vulnerability scan focused purely on CVEs will miss configuration issues that matter just as much — whether the container is set to run as root, whether unnecessary capabilities are granted, whether the image includes unnecessary tools (shells, package managers, debugging utilities) that expand what an attacker could do if the container were compromised.
Step 5: Set policy for what blocks a deployment
Not every finding should block a build — that leads to either overly permissive policies (nothing ever blocks) or overly strict ones (deployments are constantly blocked on low-impact findings). A workable policy typically blocks on critical, actively exploitable vulnerabilities and tracks lower-severity findings for scheduled remediation.
Step 6: Rescan images already in production
This is the step most commonly missed. An image that was clean at build time can become vulnerable later, when a new CVE is disclosed in one of its base image packages. Rescanning the registry — and ideally, images actively running in production — on a recurring basis catches this drift.
Step 7: Keep base images current
Much of the ongoing scanning burden can be reduced simply by keeping base images updated on a regular cadence, rather than letting them drift for months between rebuilds — an image rebuilt from a current base image will generally carry fewer known vulnerabilities than one built from a stale one.
How does Averto fit in?
Container image risk changes continuously, independent of your own build activity, since new vulnerabilities get disclosed in base image packages on an ongoing basis. Averto's continuous scanning approach extends to this layer, so drift between build-time and current risk gets caught rather than accumulating silently.
Frequently asked questions
Is scanning a Docker image once, at build time, enough?
No — new vulnerabilities can be disclosed in base image packages after the image is built, so images already in a registry or running in production need ongoing rescanning too.
Do I need to scan every layer of an image, or just the final result?
Every layer — a vulnerability or secret introduced in an intermediate layer can still be present in the final image's filesystem history even if it's not obvious from the final state alone.
Should I block deployments on every vulnerability finding?
Generally no — a workable policy blocks on critical, actively exploitable findings and tracks lower-severity ones for scheduled remediation, to avoid either alert fatigue or excessive deployment friction.
Does using a minimal base image reduce scanning burden?
Yes — fewer packages means fewer potential vulnerabilities and a smaller attack surface to track over time.