Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files12345678910111213141516171819202122232425262728293031# for deploying a React application with Node.js in a Docker container# Use Node 22 as the base imageFROM node:22-alpine# Set the working directory inside the containerWORKDIR /app# Copy package.json and package-lock.json (if you have one)COPY package*.json ./# Install dependenciesRUN npm install# Copy the rest of the application codeCOPY . .# Expose the port your React app runs onEXPOSE 7860# Change ownership of /app to the node userRUN chown -R node:node /app# Switch to the node userUSER node# Command to build the applicationCMD ["npm", "run", "build"]# Command to run the applicationCMD ["npm", "run", "start"]123456789101112131415161718192021222324252627282930313233343536373839404142434445# === Stage 1: Build ===# Create a build environmentFROM node:22-alpine AS builder# Set working directoryWORKDIR /app# Copy package files and install ALL dependencies (including devDependencies)COPY package*.json ./RUN npm install# Copy the rest of the source codeCOPY . .# Build the application# Use --no-cache to ensure a clean buildRUN npm run build --no-cache# === Stage 2: Production ===# Create a final, lean production imageFROM node:22-alpine# Set working directoryWORKDIR /app# Install ONLY production dependenciesCOPY package*.json ./RUN npm install --omit=dev# Copy assets and build output from the builder stageCOPY --from=builder /app/public ./publicCOPY --from=builder /app/.next ./.nextCOPY --from=builder /app/next.config.mjs ./next.config.mjs# Expose the portEXPOSE 7860# Change ownership to the node user for securityRUN chown -R node:node /app# Switch to the non-root userUSER node# The command to start the applicationCMD ["npm", "run", "start"]
Dockerfile+30-16