Trivy reports 200 vulnerabilities in your image. How do you reduce them?

IntermediateScenarioTrivy
Answer

Short answer

Most come from the base image. Switch to a smaller, up-to-date base (slim, Alpine, distroless, chiselled), use multi-stage builds so build tools don't ship, update OS packages and dependencies, remove what you don't need, then gate on fixable HIGH/CRITICAL issues.

Steps

  1. See where they come from
    trivy image --format table shop-api:1.4.0 | less       # OS vs language packages
    
  2. Base image — typical counts:
    Base Typical CVE count
    node:22 (full Debian) 100s
    node:22-slim dozens
    node:22-alpine / distroless few
  3. Multi-stage build — compilers, package managers and dev dependencies stay in the build stage.
  4. Update — rebuild regularly (base images get patched), apt-get upgrade in the build if needed, bump app dependencies flagged by Trivy.
  5. Remove unused packages — curl, git, shells you don't need at runtime.
  6. Gate — --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1.
  7. Keep it fixed — Dependabot/Renovate for base image tags and dependencies; scheduled rebuilds + rescans.

Example result

node:22 (≈ 400 findings) → multi-stage with node:22-alpine runtime and npm ci --omit=dev (≈ 10 findings, 0 fixable criticals).

What to say in the interview

"I check whether findings are OS or library, move to a minimal base with multi-stage builds, update packages and dependencies, strip unneeded tools, then gate on fixable HIGH and CRITICAL. Automated base-image updates and scheduled rescans keep it clean."

All Security Tools questions Roadmap: Trivy — image, file system & IaC scanning

More on Trivy