# Build stage FROM node:18-alpine AS builder WORKDIR /app # Copy package files COPY package*.json ./ # Install all dependencies (including dev) for building RUN npm ci # Copy source code COPY . . # Production stage FROM node:18-alpine WORKDIR /app # Install dumb-init for proper signal handling RUN apk add --no-cache dumb-init # Create non-root user RUN addgroup -g 1001 -S nodejs && \ adduser -S nodejs -u 1001 # Copy package files and install production dependencies only COPY package*.json ./ RUN npm ci --only=production && \ npm cache clean --force # Copy application code COPY --chown=nodejs:nodejs . . # Create necessary directories with proper permissions RUN mkdir -p logs data uploads && \ chown -R nodejs:nodejs logs data uploads # Switch to non-root user USER nodejs # Expose port (change as needed) EXPOSE 3001 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ CMD node healthcheck.js || exit 1 # Use dumb-init to handle signals properly ENTRYPOINT ["dumb-init", "--"] # Start application (change as needed) CMD ["node", "src/index.js"]