_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

Multi-stage Docker Builds

15. 07. 2025 1 min read intermediate

Cloud Intermediate

Multi-stage Docker Builds

DockerMulti-stageBuild 3 min read

Optimalizace Docker images pomocí multi-stage builds. Menší images, bezpečnější produkce.

Principle

Jeden Dockerfile, více FROM instrukcí. Build dependencies zůstávají v build stage, do finálního image jde jen runtime.

Go příklad

# Build — 1.2 GB
FROM golang:1.22 AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o server .

# Runtime — 15 MB!
FROM alpine:3.19
RUN apk add --no-cache ca-certificates
COPY --from=builder /app/server /server
USER nobody
ENTRYPOINT ["/server"]

Rust příklad

FROM rust:1.76 AS builder
WORKDIR /app
COPY . .
RUN cargo build --release

FROM debian:bookworm-slim
COPY --from=builder /app/target/release/myapp /usr/local/bin/
CMD ["myapp"]

Summary

Multi-stage = dramatické zmenšení images. Go: 1.2GB → 15MB. Node: 1GB → 150MB. Vždy používejte.

Need Help with Implementation?

Our team has experience designing and implementing modern architectures. We’re happy to help.

Free Consultation

Share:

CORE SYSTEMS tým

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