_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 Multi-Stage Builds

09. 06. 2025 1 min read intermediate

Multi-stage build: build nástroje v prvním stage, výsledek ve finálním. Dramaticky menší image.

Node.js

FROM node:18 AS builder WORKDIR /app COPY package*.json ./ RUN npm ci COPY . . RUN npm run build FROM nginx:alpine COPY –from=builder /app/dist /usr/share/nginx/html

40 MB místo 1.2 GB

Go

FROM golang:1.22 AS builder WORKDIR /app COPY . . RUN CGO_ENABLED=0 go build -o server . FROM scratch COPY –from=builder /app/server /server ENTRYPOINT [“/server”]

15 MB

Python

FROM python:3.12 AS builder COPY requirements.txt . RUN pip install –user –no-cache-dir -r requirements.txt FROM python:3.12-slim COPY –from=builder /root/.local /root/.local COPY . . CMD [“python”, “app.py”]

  • Pojmenujte stages (AS builder)
  • Dependency soubory první → lepší cache
  • alpine/slim/scratch base
  • Používejte .dockerignore

Menší = lepší

Multi-stage = menší image, menší attack surface, rychlejší pull.

dockermulti-stagebuild
Share:

CORE SYSTEMS tým

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