Safeguard
Developer Tools•

How do you keep container scans fast enough for CI?

Slow scans get switched off. Cut container scan time in CI: cache data, scan once per digest, trim images and split blocking from deep checks.

Safeguard Security Team
3 min read

Keep CI scans fast by caching the advisory database, scanning each image digest once, shrinking the image, running the blocking check on changed images only, and moving deep analysis to a scheduled job. A scan developers wait on for ten minutes will eventually be skipped.

Where the time goes

A container scan has four costs: fetching the image, unpacking layers, loading advisory data and matching. Fetching and database download are often the largest. Matching a package list is cheap. Optimize in that order.

Practical steps

  1. Cache the vulnerability database between runs. Re-downloading it per job wastes minutes. Refresh it on a schedule, not per commit.
  2. Scan before push from a local archive or layout, so you skip a registry round trip. See scanning without a daemon.
  3. Scan each digest once. If the image bytes did not change, reuse the earlier result and only refresh the advisory data.
  4. Make images smaller. Fewer layers and fewer packages mean less to unpack and fewer findings. Multi-stage builds help.
  5. Scan only what changed. In a monorepo, build and scan the services touched by the commit.
  6. Run scans in parallel with tests, not after them.
  7. Give the job enough CPU and disk. Unpacking is disk heavy.

Split blocking from deep

CheckWhereBlocks merge?
Known critical, fixable, exploitedCI, every buildYes
Full severity range, license, secretsCI, on release branchPolicy dependent
Deep rescan of all deployed imagesScheduled jobNo, alerts only

Keeping the blocking rule narrow keeps it fast and trusted. A wide rule produces failures developers cannot act on, and they will route around it.

A quick example of the arithmetic

Suppose a scan spends most of its time downloading the advisory database and pulling the image. Caching the database removes one cost. Scanning from a local archive removes the other. The matching step, the part you actually care about, may take only seconds. Look at a timing breakdown of your own job before tuning, because the slow step is often not the one people expect.

Measure it

Record scan duration in your pipeline metrics. Set a target, for example under two minutes for the blocking check, and treat a regression like any other performance bug. If the scan is slow because the image is huge, that is useful feedback about the image.

Try it yourself

Click through it at your own pace, or open it full screen.

Watch how a gate reports a result inside the pull request, which is what a fast scan makes possible.

Quick check

Can I skip the scan for unchanged images?

You can reuse the image analysis by digest but still refresh the advisory match, because the data changes.

Is failing the build on every high finding sensible?

Rarely at first. Start with fixable, exploited findings and widen as the backlog shrinks.

Safeguard offers a CLI and CI integration for dependency and SBOM scanning with policies and gates, and a free scan to try first.

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.