Docker cookbook · Intermediate
Scan images for vulnerabilities in CI
Find known CVEs in base images and dependencies before images reach production.
Approach
Scan the built image with Docker Scout or Trivy, fail the build only on critical or high vulnerabilities that have a fix available, and rebuild regularly on patched bases.
Solution
docker scout cves --only-severity critical,high --only-fixed --exit-code app:dev
# or
trivy image --severity CRITICAL,HIGH --ignore-unfixed --exit-code 1 app:dev
Pitfalls
- Failing builds on every unfixed low-severity finding: teams learn to ignore the scanner.
- Scanning once at build time only; new CVEs appear for old images, so scan running images too.
Variations
- Generate an SBOM (
docker buildx build --sbom=true) and scan it continuously. - Track base image freshness and rebuild weekly.
Further reading: Docker Scout
Reference: https://docs.docker.com/scout/
More Docker recipes
- Add a healthcheck to an HTTP service
- Build a layered image for a Spring Boot app
- Build a production image for a Node.js service
- Build a production image for a Python web app
- Build, cache and push images in GitHub Actions
- Build one image tag for amd64 and arm64
- Configure nginx from environment variables
- Develop with Compose and live reload