Menu

How to Shrink Python & Node Docker Images by 85% and Pass Trivy Scans on the First Try (2026 Multi-Stage Guide)
📰

How to Shrink Python & Node Docker Images by 85% and Pass Trivy Scans on the First Try (2026 Multi-Stage Guide)

DEV Community: docker·Woojin LIM, Ryan·2 days ago
#Fp4AyAzU
#devtodocker#devto#dev#trivy#venv
Long article (549 words) — no AI summary yet.
Reading 0:00
15s threshold

A single naive FROM node:22 or FROM python:3.12 Dockerfile routinely ships a 1.1 GB container image packed with gcc , curl , package-manager caches, root privileges, and 40+ HIGH/CRITICAL CVEs flagged by Trivy in CI.

Here is the exact 2026 hardened multi-stage Dockerfile blueprint that drops image size from ~1.1 GB to <120 MB , eliminates build-tool attack surface, and passes CIS + Trivy scans cleanly.

1. The Hardened Multi-Stage Python (FastAPI) Blueprint

# syntax=docker/dockerfile:1.7 FROM python:3.12-slim AS builder

ENV PIP_NO_CACHE_DIR = 1 \ PIP_DISABLE_PIP_VERSION_CHECK = 1

WORKDIR /build COPY requirements.txt .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.