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
- See where they come from
trivy image --format table shop-api:1.4.0 | less # OS vs language packages - Base image — typical counts:
Base Typical CVE count node:22(full Debian)100s node:22-slimdozens node:22-alpine/ distrolessfew - Multi-stage build — compilers, package managers and dev dependencies stay in the build stage.
- Update — rebuild regularly (base images get patched),
apt-get upgradein the build if needed, bump app dependencies flagged by Trivy. - Remove unused packages — curl, git, shells you don't need at runtime.
- Gate —
--severity HIGH,CRITICAL --ignore-unfixed --exit-code 1. - 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."
More on Trivy
What is Trivy and how do you scan an image with it?BeginnerWhat is a CVE and what do severity levels mean?BeginnerWhat is Trivy and what can it scan?BeginnerHow do you scan a Docker image with Trivy?BeginnerHow do you fail a CI build when Trivy finds HIGH or CRITICAL vulnerabilities?BeginnerWhat does trivy fs do?Beginner