Lorixen.
EN

Scanning Docker images for vulnerabilities without the noise

Short answer: Run an image scanner such as Trivy against every image your CI builds, and fail the build only for high and critical vulnerabilities that already have a fix. Shrink the report at the source by using a small, current base image and multi-stage builds, then rebuild regularly so OS patches flow in. Anything you decide to accept goes in an ignore file with a reason and an expiry date, so it's reviewed rather than forgotten.

Why scan images at all

A container image contains more than your code: an operating system layer, system libraries, language runtimes and every dependency you installed. Each of those can have publicly known vulnerabilities (CVEs). Your app code may be perfect while the image ships an outdated library with a published exploit.

Trivy, an open-source scanner, describes what it can scan, including container images, filesystems and Git repositories, and what it looks for: OS packages and software dependencies, known vulnerabilities, misconfigurations, secrets and software licences. Other scanners, including ones built into container registries, do similar jobs.

The first report is always alarming

Point a scanner at a typical image built on a full operating system base and you'll get a long list, many items marked "low", plenty with no fix available, and a handful of serious ones. Teams often react by either ignoring the whole report or trying to fix everything. Neither works. The goal is a small, meaningful list you act on every time.

Step 1: reduce what's in the image

The cheapest vulnerability is one you don't ship:

  • Use a slim or minimal base image rather than a full operating system image. Fewer packages, fewer CVEs.
  • Use multi-stage builds. Compile and install build tools in one stage, then copy only the result into a clean runtime stage. Compilers and package caches stay out of production.
  • Keep the base image current. Pin a specific version for repeatable builds, and update it on a schedule.
  • Remove what you don't need, such as debugging tools installed "just in case".

Re-scan after each change; it's the easiest way to see the effect.

Step 2: filter to what matters

Trivy's documentation describes two filters that make reports manageable:

  • --severity HIGH,CRITICAL shows only the more serious findings.
  • --ignore-unfixed hides vulnerabilities for which no fixed version exists yet. The docs describe it as shorthand for ignoring findings with statuses such as affected, will not fix, fix deferred and end of life, so it shows only those you can fix by updating.

A sensible CI rule: fail the build when there are fixable high or critical vulnerabilities, and report everything else without failing. Unfixable findings aren't harmless, but there's no update to apply; track them and watch for fixes.

Step 3: a reviewed ignore list

Sometimes a finding doesn't apply to you, for example a vulnerability in a feature your app never uses. Trivy supports a .trivyignore file listing vulnerability IDs, with comments explaining why, and an exp: date after which the ignore expires. Its docs also describe VEX documents for formally stating that a product isn't affected, and a flag to show suppressed findings when you want to review them.

Rules that keep an ignore list honest:

  • Every entry has a comment with the reason and who decided.
  • Every entry has an expiry date, so it comes back for review.
  • The file is in version control and changes go through code review.

Step 4: run it in CI and on a schedule

  • Scan on every build, before pushing the image to your registry, so a new vulnerable dependency is caught in the pull request that added it.
  • Scan on a schedule as well, such as weekly, because new CVEs are published against images you already built. An image that was clean last month may not be today.
  • Rebuild regularly, even without code changes, to pick up patched base images.
  • Pin the CI actions and tool versions you use for scanning, as with any third-party tool in your pipeline.

Step 5: fix in the right place

When a fixable finding appears, the report shows which package it's in:

  • OS package: update the base image or run the package manager's upgrade during the build.
  • Language dependency: update it in your lock file, then rebuild.
  • A dependency of a dependency: update the parent package, or use your package manager's override feature if the parent is slow to update.

Re-run the scan to confirm, then merge.

Don't forget secrets and configuration

The same scanners can flag secrets accidentally baked into images, such as API keys in a copied .env file, and risky Dockerfile settings like running as root. These are often more urgent than a low-severity CVE, because they're directly usable. Add a .dockerignore file so local config files never enter the build context.

A worked example

An illustrative Perth booking SaaS ran its API in a container built on a full operating system image. The first scan listed several hundred findings and the team didn't know where to start. They moved to a slim base with a multi-stage build, which removed most of the list. CI now fails only on fixable high and critical issues, a short .trivyignore with reasons and expiry dates covers two accepted findings, and a weekly scheduled scan rebuilds and checks the production image.

FAQ

Does a clean scan mean the image is secure?

No. It means no known vulnerabilities were found in recognised packages. Your own code and configuration still need review.

What about vulnerabilities with no fix?

Track them, check whether the affected component is actually used, and look for an alternative package if one stays unfixed for long.

Should I scan images from public registries before using them?

Yes, especially base images and third-party tools you run in production.

Will scanning slow down CI?

A little, mostly for downloading the vulnerability database; caching it helps.

If your container scans produce reports nobody acts on, send us an example and we'll help you set rules your team can follow.

Sources

WhatsAppBook a call