_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

Dockerfile Best Practices

17. 06. 2024 1 min read intermediate

Cloud Intermediate

Dockerfile Best Practices

DockerDockerfileOptimalizace 3 min read

Optimalizace Dockerfile pro menší images, rychlejší build a bezpečnost.

Multi-stage build

# Build stage
FROM node:20 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Production stage
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
USER node
EXPOSE 3000
CMD ["node", "dist/server.js"]

Best Practices

  • Používejte alpine base images
  • Oddělte COPY package.json od COPY . (layer caching)
  • Přidejte .dockerignore
  • Spouštějte jako non-root user
  • Používejte specific tags, ne :latest
  • Minimalizujte počet vrstev

.dockerignore

node_modules
.git
.env
*.md
Dockerfile
docker-compose.yml

Summary

Správný Dockerfile = malý image, rychlý build, bezpečný runtime. Multi-stage builds jsou základ.

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.