Dockerfile hinzugefügt
This commit is contained in:
38
Dockerfile
Normal file
38
Dockerfile
Normal file
@@ -0,0 +1,38 @@
|
||||
# ----- Stufe 1: Builder -----
|
||||
# Diese Stufe baut die TypeScript-App und installiert alle Dependencies
|
||||
FROM node:20-alpine AS builder
|
||||
WORKDIR /app
|
||||
|
||||
# Kopiere package.json und lock-Datei
|
||||
COPY package*.json ./
|
||||
|
||||
# Installiere alle Dependencies (inkl. devDependencies für den Build)
|
||||
RUN npm install
|
||||
|
||||
# Kopiere den gesamten Quellcode
|
||||
COPY . .
|
||||
|
||||
# Führe den Build-Prozess aus (compiliert TS zu JS in /dist)
|
||||
RUN npm run build
|
||||
|
||||
# Entferne devDependencies, um node_modules zu verkleinern
|
||||
RUN npm prune --production
|
||||
|
||||
# ----- Stufe 2: Production -----
|
||||
# Diese Stufe erstellt das finale, schlanke Image nur mit dem Nötigsten
|
||||
FROM node:20-alpine
|
||||
WORKDIR /app
|
||||
|
||||
# Setze den User auf 'node', um nicht als root zu laufen (Security Best Practice)
|
||||
USER node
|
||||
|
||||
# Kopiere nur die notwendigen Dateien aus der 'builder'-Stufe
|
||||
COPY --from=builder --chown=node:node /app/node_modules ./node_modules
|
||||
COPY --from=builder --chown=node:node /app/dist ./dist
|
||||
COPY --from=builder --chown=node:node /app/package.json ./package.json
|
||||
|
||||
# Das .env.example im Repo zeigt, dass der Port auf 3000 voreingestellt ist.
|
||||
EXPOSE 3000
|
||||
|
||||
# Standard-Startbefehl für eine NestJS-Produktions-App
|
||||
CMD ["node", "dist/main.js"]
|
||||
Reference in New Issue
Block a user