How do you scan Docker images for vulnerabilities in a CI/CD pipeline?
Image scanning should be a mandatory gate before pushing to production. Tools and integration steps:
- Trivy (Aqua): Fast, comprehensive, easy CI integration.
trivy image myapp:latest - Snyk: Deep dependency scanning with developer-friendly output.
- Docker Scout: Built into Docker Hub.
- Grype: From Anchore, works well with SBOM workflows.
# GitHub Actions example
- name: Scan image with Trivy
uses: aquasecurity/trivy-action@master
with:
image-ref: myapp:${{ github.sha }}
severity: CRITICAL,HIGH
exit-code: 1 # Fail the pipeline on critical vulnerabilities