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

@@ -1,13 +1,40 @@
# Use node 18 alpine for smaller image size
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Copy package files
COPY package*.json ./
# Install all dependencies (including devDependencies needed for build)
# Set npm config for better CI performance
RUN npm ci --prefer-offline --no-audit
# Copy source code
COPY . .
# Set Node.js memory limit for build (helpful in constrained environments)
ENV NODE_OPTIONS="--max-old-space-size=1024"
# Build the application
RUN npm run build
# Remove devDependencies after build to reduce image size
RUN npm prune --omit=dev
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# Change ownership of the app directory
RUN chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
CMD ["npm", "start"]