Dockerfile 603 B

123456789101112131415161718192021222324252627282930313233
  1. FROM node:18-alpine
  2. WORKDIR /app
  3. # Install curl for health check
  4. RUN apk add --no-cache curl
  5. # Copy package files
  6. COPY package*.json ./
  7. # Install dependencies
  8. RUN npm install --only=production
  9. # Copy source code
  10. COPY . .
  11. # Create non-root user
  12. RUN addgroup -g 1001 -S nodejs
  13. RUN adduser -S nodejs -u 1001
  14. # Change ownership of app folder
  15. RUN chown -R nodejs:nodejs /app
  16. USER nodejs
  17. # Expose port
  18. EXPOSE 4000
  19. # Health check
  20. HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  21. CMD curl -f http://localhost:4000/health || exit 1
  22. # Start the application
  23. CMD ["npm", "start"]