Skip to content
_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN DE
Let's talk

Docker Image: From 5 GB to 50 MB

14. 03. 2024 1 min read intermediate

Your Docker image is 5 GB? Here is how to get it down to 50 MB.

Step 1: Measure

docker images myapp docker history myapp:latest

Step 2: Alpine Base

Docker Image: From 5 GB to 50 MB

FROM node:20-alpine # → 180 MB

Step 3: Multi-stage Build

FROM node:20-alpine AS build WORKDIR /app COPY package*.json ./ RUN npm ci –production COPY . . RUN npm run build

FROM node:20-alpine COPY –from=build /app/dist ./dist COPY –from=build /app/node_modules ./node_modules CMD [“node”, “dist/index.js”]

Step 4: Distroless

FROM gcr.io/distroless/nodejs20-debian12 COPY –from=build /app/dist /app CMD [“/app/index.js”]

Step 5: .dockerignore

node_modules .git *.md Dockerfile tests

Step 6: Minimize Layers

RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*

Results

  • node:20 = 1.1 GB
  • node:20-alpine = 180 MB
  • Multi-stage + alpine = 80 MB
  • Distroless = 50 MB
  • Go static binary + scratch = 10 MB

Tip

Smaller image = faster deploy, less attack surface, less storage. Always worth it.

dockeroptimizationdevops
Share:

CORE SYSTEMS team

We build core systems and AI agents that keep operations running. 15 years of experience with enterprise IT.