# Use Node.js 18 Alpine for smaller image size | |
FROM node:18-alpine | |
# Set working directory | |
WORKDIR /app | |
# Install system dependencies | |
RUN apk add --no-cache \ | |
python3 \ | |
make \ | |
g++ \ | |
curl \ | |
&& ln -sf python3 /usr/bin/python | |
# Copy package files | |
COPY package*.json ./ | |
# Install dependencies (including dev dependencies for build) | |
RUN npm ci | |
# Copy source code | |
COPY . . | |
# Build the application | |
RUN npm run build | |
# Clean up dev dependencies after build | |
RUN npm prune --production | |
# Create non-root user for security | |
RUN addgroup -g 1001 -S nodejs && \ | |
adduser -S nextjs -u 1001 | |
# Change ownership of the app directory | |
RUN chown -R nextjs:nodejs /app | |
# Switch to non-root user | |
USER nextjs | |
# Expose port | |
EXPOSE 7860 | |
# Health check | |
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ | |
CMD curl -f http://localhost:7860/api/health || exit 1 | |
# Start the application | |
CMD ["npm", "start"] |