Zum Inhalt springen
_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
Referenzen Technologien Blog Know-how Tools
Über uns Zusammenarbeit Karriere
CS EN DE
Lassen Sie uns sprechen

Dockerfile Best Practices

17. 06. 2024 1 Min. Lesezeit intermediate

Cloud Pokročilý

Dockerfile Best Practices

DockerDockerfileOptimalizace 3 min čtení

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

Shrnutí

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

Potřebujete pomoct s implementací?

Náš tým má zkušenosti s návrhem a implementací moderních architektur. Rádi vám pomůžeme.

Nezávazná konzultace

Teilen:

CORE SYSTEMS tým

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