Interview Prep/DevSecOps/Container image and IaC scanning

Trivy scan job sometimes takes 2 seconds and passes, sometimes 4 minutes and fails, for the same image

AdvancedTroubleshootingContainer image and IaC scanning
Answer

Likely causes → A stale scan result cache keyed by image ID is reused, or the DB update failed silently with --skip-db-update and an old DB.

Diagnose →

trivy image --debug myapp:1.4 2>&1 | grep -E "DB|cache"
trivy --version   # shows DB version and UpdatedAt

Fix → Clear or scope the cache (trivy clean --scan-cache), refresh the DB at job start, and print DB metadata in logs.

Prevent → Fail the job if the DB is older than a threshold, so results are reproducible and explainable.

All DevSecOps questions

More on Container image and IaC scanning