Dockerfile improvement

This commit is contained in:
Stefan Hardegger
2025-07-28 14:28:01 +02:00
parent a501b27169
commit 860bf02d56
4 changed files with 71 additions and 2 deletions

View File

@@ -0,0 +1,42 @@
# Multi-stage build for better caching and smaller final image
FROM node:18-alpine AS dependencies
WORKDIR /app
COPY package*.json ./
RUN npm ci
FROM node:18-alpine AS builder
WORKDIR /app
COPY --from=dependencies /app/node_modules ./node_modules
COPY . .
# Increase memory limit for build
ENV NODE_OPTIONS="--max-old-space-size=2048"
RUN npm run build
FROM node:18-alpine AS runner
WORKDIR /app
# Install dumb-init
RUN apk add --no-cache dumb-init
# Create non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# Copy necessary files
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# Set correct permissions
RUN chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
ENTRYPOINT ["dumb-init", "--"]
CMD ["node", "server.js"]