Keeping up with aging Docker images

| 708 words

Introduction

Keeping up with security updates is becoming increasingly important, even for a personal server. Linux distributions like Ubuntu already allow you to configure automatic (unattended) security upgrades. I use this feature on my own server and have never had any issues with it (I can tolerate brief downtime when the server reboots).

However, all my applications run as Docker containers. These applications do not rely on Ubuntu’s patched system libraries; instead, they ship their own. This is the trade-off of the containerized approach: running five applications usually means managing five different sets of dependencies (OpenSSL, shell utilities, .NET, Python, Node.js, etc.). In the book Podman in Action, the author quotes a colleague: “Container images don’t age like wine; they age like cheese. As the image gets older, it gets stinky.”

Updating the host operating system without updating the application images leaves a significant gap. Fortunately, this is a well-known problem with several effective solutions.

Repeatable Deployment Process

My workstation runs Windows, which does not natively support building Linux container images. To work around this, my original deployment process compiled the application binaries locally and transferred them to the server via SCP. The server then combined those binaries with the base runtime using a Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine3.22

RUN apk upgrade --no-cache && apk add --no-cache \
    ca-certificates

RUN apk add --no-cache \
	bash \
	s6-overlay

COPY rootfs /

This approach had two major downsides:

  • The final set of installed dependencies was known only after the image had been built on the server.
  • Although the application source code version was pinned, the resulting Docker image was not deterministic, as package managers like apk pull the latest available packages during the build step.

To scan my applications for vulnerabilities, I first needed a predictable build process where the image is built entirely on the client machine. On Windows, this can be achieved using either WSL (Windows Subsystem for Linux) or a virtual machine.

Once the image is built locally, I use Podman to export it as a tarball. This archive contains the compiled application, the runtime, and every underlying dependency:

podman build --pull=newer -t gregor/app \
  "$CONTEXT"

podman save -o app.tar gregor/app

The deployment process then transfers this archive to the server. The server no longer downloads packages or builds images; it simply loads the image from the archive and starts the container.

Software Bill of Materials (SBOM)

The image archive generated in the previous step contains all the dependencies our application needs. CycloneDX provides an open standard for cataloging these components, known as a Software Bill of Materials (SBOM).

This standard is widely supported across the industry. I chose the trivy security scanner, which can inspect a saved image archive directly and generate an SBOM:

trivy image --input app.tar \
  --format cyclonedx --output app.cdx.json --quiet

Scanning for Vulnerabilities

Once the SBOM has been generated, Trivy can check for known vulnerabilities against multiple advisory sources. The scanning process is straightforward:

trivy sbom app.cdx.json \
  --format table --output app.vulns.txt

The scan outputs a report with a summary, and a details section for every vulnerability detected. An excerpt from the report is shown below:

Target Type Count
app.cdx.json (alpine 3.22.3) alpine 74
app.deps.json dotnet-core 1
Microsoft.AspNetCore.App.deps.json dotnet-core 16
Microsoft.NETCore.App.deps.json dotnet-core 18

Legend:

  • -: Not scanned
  • 0: Clean (no security findings detected)

Fixing the Vulnerabilities

An effective way to remediate these issues is to create a custom skill for an AI agent. The agent parses the scan report and bumps vulnerable dependencies to safe versions. If automated tests are available, the agent can run them to ensure no regressions were introduced. Finally, it produces an updated report reflecting the applied fixes:

Severity before after
CRITICAL 4 0
HIGH 42 0
MEDIUM 30 0
LOW 33 0

Conclusion

The rate at which vulnerabilities are discovered in open-source projects continues to accelerate due to automated security tooling. Because container images are isolated from the host OS, regular system upgrades will not keep them secure. We must actively manage them ourselves.

One common solution is to rely on CI/CD platforms like GitHub or GitLab, which offer container scanning out of the box. However, the local SBOM generation and scanning pipeline demonstrated here provides a practical, lightweight alternative when those platforms are not part of your workflow.