---
title: "Secure by Design: A Proactive Testing Approach with Testcontainers, Docker Scout, and Hardened Images"
description: "Swapping a Node.js API's node:22-slim base image for a Docker Hardened Image (distroless dhi-node:22) eliminated all critical and high CVEs flagged by Docker Scout, including Debian 12's CVE-2025-6020, while avoiding the musl compatibility risk of switching to Alpine."
url: "https://swe.quest/articles/secure-by-design-a-proactive-testing-approach-with-testcontainers-docker-scout-3bd5cb7e139bb4be"
canonical: "https://www.docker.com/blog/a-shift-left-approach-with-docker/"
source: "Docker"
published: "2025-08-28"
difficulty: "medium"
kind: "How-to"
reading_minutes: 10
tags: ["containers","supply-chain-security","testing","typescript"]
---

# Secure by Design: A Proactive Testing Approach with Testcontainers, Docker Scout, and Hardened Images

A post on [Docker](https://swe.quest/sources/docker.md), published 2025-08-28, 10 min read, How-to. Original: [https://www.docker.com/blog/a-shift-left-approach-with-docker/](https://www.docker.com/blog/a-shift-left-approach-with-docker/)

## Summary

Swapping a Node.js API's node:22-slim base image for a Docker Hardened Image (distroless dhi-node:22) eliminated all critical and high CVEs flagged by Docker Scout, including Debian 12's CVE-2025-6020, while avoiding the musl compatibility risk of switching to Alpine. The walkthrough builds images with SBOM and provenance attestations via buildx, scans and compares them with Docker Scout, and uses -dev and runtime DHI variants in a multi-stage Dockerfile. The image shrank from 80 MB and 427 packages to 41 MB and 123 packages. Testcontainers-based API tests against real Postgres confirm the app still works in under 20 seconds, and VEX attestations can be exported for external scanners like Grype or Trivy.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Containers](https://swe.quest/tags/containers.md) (Infrastructure)
- [Supply chain security](https://swe.quest/tags/supply-chain-security.md) (Security)
- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)
- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)

## Prerequisites

- Dockerfile multi-stage builds
- Node.js testing basics ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- CVE scanning concepts ([easy posts on Vulnerability research](https://swe.quest/tags/vulnerability-research.md?difficulty=easy))

## Keywords

Testcontainers, Docker Scout, Docker Hardened Images, OpenVEX, SBOM, PostgreSQL, Grype, Trivy

## Related posts

- [Making the Most of Your Docker Hardened Images Enterprise Trial – Part 1](https://swe.quest/articles/making-the-most-of-your-docker-hardened-images-enterprise-trial-part-1-61a4db14eac1477b.md): Docker · 2025-11-14 · Medium · 10 min read · Containers, Supply chain security, Security
  Docker Hardened Images (DHI) strip base images down to the minimum runtime, removing package managers, shells and utilities while keeping distro compatibility.
- [From Security Blocked to Prod Ready: ClickHouse on Docker Hardened Images](https://swe.quest/articles/from-security-blocked-to-prod-ready-clickhouse-on-docker-hardened-images-fbdddd6267212370.md): Docker · 2026-04-30 · Medium · 11 min read · Containers, Supply chain security, Kubernetes, Security
  Security scanners block the standard ClickHouse image because its Ubuntu 22.04 base ships unused packages carrying unpatched CVEs, such as wget (CVE-2021-31879) and tar.
- [Docker Hardened Images enhanced vulnerability scanning with Docker and Aikido](https://swe.quest/articles/docker-hardened-images-enhanced-vulnerability-scanning-with-docker-and-aikido-d49b93c672989876.md): Docker · 2026-06-11 · Medium · 4 min read · Supply chain security, Containers, Security
  Aikido now scans Docker Hardened Images (DHI) using Docker's signed OpenVEX attestations, automatically suppressing CVEs that Docker has marked fixed or not affected so triage queues show only findings that actually apply.
- [CNCF Score project improved its security posture by joining the Docker-Sponsored Open Source Program](https://swe.quest/articles/cncf-score-project-improved-its-security-posture-by-joining-the-docker-203499a569bdd49d.md): Docker · 2026-11-05 · Medium · 8 min read · Supply chain security, Containers, CI/CD, Open source
  Score, a CNCF Sandbox project, hardened its container image supply chain by moving images to Docker Hub, adding Docker Scout PR comparisons that report CVEs, package changes and policy compliance, and switching base images to Docker Hardened Images.
- [Making the Most of Your Docker Hardened Images Enterprise Trial – Part 3](https://swe.quest/articles/making-the-most-of-your-docker-hardened-images-enterprise-trial-part-3-074fb74ac78adf47.md): Docker · 2026-01-25 · Medium · 8 min read · Containers, Supply chain security, Security
  Docker Hardened Images (DHI) ship without package managers, shells or utilities, so adding agents, CA certificates or libraries needs one of two patterns.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
