# Use official Node.js runtime as base image FROM node:18-alpine # Set working directory in container WORKDIR /app # Copy package files first (for better Docker layer caching) COPY package*.json ./ # Install dependencies RUN npm ci --only=production && npm cache clean --force # Create non-root user for security RUN addgroup -g 1001 -S nodejs && \ adduser -S nodejs -u 1001 # Copy application code COPY src/ ./src/ # Change ownership to nodejs user RUN chown -R nodejs:nodejs /app USER nodejs # Expose port EXPOSE 3000 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD node -e "require('http').get('http://localhost:3000/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })" # Start the application CMD ["npm", "start"]