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.
2026-06-30T10:44:19.882Z FATAL image scan error: scan error: unable to scan image:
analyze error: timeout: context deadline exceededCommon 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.
trivy image --timeout 15m \
--exit-code 1 --severity HIGH,CRITICAL myimage:latestReduce 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.
- 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.