← All insightsIntegration

How to use Docker with Trivy

CodeWizard Engineering · 6 May 2025 · 3 min read · Intermediate

Docker and Trivy are a common pairing in a modern DevOps stack. Here is how they fit together and a practical way to wire them up.

Where Docker fits

Docker builds, ships and runs applications inside containers - isolated processes that bundle the code, runtime and libraries so 'works on my machine' stops being a problem.

dockerfile
# syntax=docker/dockerfile:1
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-alpine AS run
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
USER node
EXPOSE 3000
CMD ["node", "dist/server.js"]

Where Trivy fits

Trivy is an open-source security scanner that finds CVEs, misconfigurations, secrets and license issues across container images, filesystems, Git repos, IaC and live Kubernetes clusters.

yaml
# trivy.yaml
severity:
  - HIGH
  - CRITICAL
vulnerability:
  ignore-unfixed: true
exit-code: 1

Making them work together

  • Pin base image tags (or digests) instead of :latest for reproducibility
  • Order layers from least- to most-frequently changed to maximize cache hits
  • Gate on HIGH/CRITICAL with ignore-unfixed, then tighten over time
  • Scan images, IaC and filesystems - not just one surface

Want this pairing set up properly, with docs and handover? That is exactly the kind of work CodeWizard's embedded senior engineers do - and both Docker and Trivy have active community groups you can join for free.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult