_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
Let's talk

Docker image: z 5 GB na 50 MB

14. 03. 2024 1 min read intermediate

Vaše Docker image má 5 GB? Tady je jak ji dostat na 50 MB.

Krok 1: Změřte

docker images myapp
docker history myapp:latest

Krok 2: Alpine base

FROM node:20 → 1.1 GB

FROM node:20-alpine # → 180 MB

Krok 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”]

Krok 4: Distroless

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

Krok 5: .dockerignore

node_modules .git *.md Dockerfile tests

Krok 6: Minimalizujte vrstvy

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

Výsledky

  • 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

Menší image = rychlejší deploy, méně attack surface, méně storage. Vždy se vyplatí.

dockeroptimalizacedevops
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.