Spaces:
Runtime error
Runtime error
| # Use an official Node.js runtime as a parent image | |
| FROM node:16 as builder | |
| # Set the working directory | |
| WORKDIR /app | |
| # Copy package.json and install dependencies | |
| COPY package*.json ./ | |
| RUN npm install | |
| # Copy the rest of the application code | |
| COPY . . | |
| # Build the React app | |
| RUN npm run build | |
| # Use an Nginx image to serve the built app | |
| FROM nginx:alpine | |
| # Set user to root temporarily to fix permissions | |
| USER root | |
| # Fix permissions for nginx cache and /run directory | |
| RUN mkdir -p /var/cache/nginx /run && chmod -R 777 /var/cache/nginx /run | |
| # Copy built React files | |
| COPY --from=builder /app/build /usr/share/nginx/html | |
| # (Optional) Fix Nginx listen port if needed | |
| RUN sed -i 's/listen\s\+80;/listen 8080;/' /etc/nginx/conf.d/default.conf | |
| # Expose correct port | |
| EXPOSE 8080 | |
| # Start Nginx | |
| CMD ["nginx", "-g", "daemon off;"] | |