Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files11234345656798911121011151213141815161718192021222324252627282930313233343536372138394024414243272829304445# for deploying a React application with Node.js in a Docker container# === Stage 1: Build ===# Create a build environmentFROM node:22-alpine AS builder
# Use Node 22 as the base imageFROM node:22-alpine
# Set the working directory inside the container# Set working directoryWORKDIR /app
# Copy package.json and package-lock.json (if you have one)# Copy package files and install ALL dependencies (including devDependencies)COPY package*.json ./
# Install dependenciesRUN npm install
# Copy the rest of the application code# Copy the rest of the source codeCOPY . .
# Expose the port your React app runs on# 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 of /app to the node user# Change ownership to the node user for securityRUN chown -R node:node /app
# Switch to the node user# Switch to the non-root userUSER node
# Command to build the applicationCMD ["npm", "run", "build"]
# Command to run the application# The command to start the applicationCMD ["npm", "run", "start"]Dockerfile+30-16