Skip to content
Latchkey

Trivy "context deadline exceeded" timeout on large images in CI

Trivy has a default timeout for analyzing an image (5 minutes historically). A very large image with many layers and packages can exceed it, and Trivy aborts with "context deadline exceeded". Raising --timeout and slimming the image or scan scope resolves it.

What this error means

A scan that worked on small images fails on a large one with "analyze error: timeout: context deadline exceeded" partway through layer analysis.

Trivy
2026-06-30T10:44:19.882Z	FATAL	image scan error: scan error: unable to scan image:
analyze error: timeout: context deadline exceeded

Common causes

A large image outgrew the default timeout

Many layers or thousands of packages make analysis slow, and the default --timeout elapses before Trivy finishes.

Slow disk or an uncached DB compounds the delay

Downloading the DB and unpacking layers on a slow runner adds time, pushing total analysis past the deadline.

How to fix it

Raise the timeout for large images

Give the scan enough time to finish instead of failing on the deadline.

Terminal
trivy image --timeout 15m \
  --exit-code 1 --severity HIGH,CRITICAL myimage:latest

Reduce work: cache the DB and slim the image

Cache the DB so the scan starts faster, and trim the image (multi-stage build, fewer layers) so there is less to analyze.

.github/workflows/ci.yml
- uses: actions/cache@v4
  with:
    path: ~/.cache/trivy
    key: trivy-db-${{ github.run_id }}
    restore-keys: trivy-db-

How to prevent it

  • Set a generous --timeout for known-large images.
  • Slim images with multi-stage builds so scans are quicker.
  • Cache the DB so scan setup does not eat the budget.

Frequently asked questions

What causes "Trivy "context deadline exceeded""?
Many layers or thousands of packages make analysis slow, and the default --timeout elapses before Trivy finishes.
How do I fix Trivy "context deadline exceeded"?
Give the scan enough time to finish instead of failing on the deadline.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card