changed docker

This commit is contained in:
2025-08-27 17:37:22 -05:00
parent 93301696cf
commit 1832f98d40
3 changed files with 82 additions and 30 deletions

View File

@@ -1,40 +1,61 @@
# Multi-stage build for production
FROM node:22-alpine AS deps
# ---------- Base for installs ----------
FROM node:22-alpine AS base
WORKDIR /app
# ---------- Production deps ----------
FROM base AS deps
COPY package*.json ./
# nur Prod-Deps für die runner-Stage (schnellerer Start, kleineres Image)
RUN npm ci --only=production
FROM node:22-alpine AS builder
WORKDIR /app
# ---------- Full deps + Build ----------
FROM base AS builder
COPY package*.json ./
# volle Deps inkl. devDependencies
RUN npm ci
# Rest des Codes
COPY . .
RUN npm run build
# ---------- Development stage ----------
FROM base AS dev
ENV NODE_ENV=development
# nur package-Dateien kopieren, damit npm install gecacht wird
COPY package*.json ./
RUN npm install
# Quellcode kommt zur Laufzeit per Bind-Mount aus Compose
# (sorgt für Hot Reload)
EXPOSE 3000
ENV HOSTNAME="0.0.0.0"
CMD ["npm", "run", "dev"]
# ---------- Production runner ----------
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Create non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# non-root user
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
# Copy built application
# für Healthcheck
RUN apk add --no-cache curl
# statische Assets & Standalone-Output aus builder
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Health check
# Health check (pfad anpassen, falls dein Endpoint anders heißt)
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/api/health || exit 1
CMD curl -fsS http://127.0.0.1:3000/api/health || exit 1
# Next.js standalone startet über server.js
CMD ["node", "server.js"]