Spaces:
Sleeping
Sleeping
Create Dockerfile
Browse files- Dockerfile +31 -0
Dockerfile
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Stage 1: Build the application
|
| 2 |
+
FROM node:20-alpine AS builder
|
| 3 |
+
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# Copy package files first to leverage Docker cache for dependencies
|
| 7 |
+
COPY package*.json ./
|
| 8 |
+
|
| 9 |
+
# Install dependencies
|
| 10 |
+
RUN npm install
|
| 11 |
+
|
| 12 |
+
# Copy the rest of the application source code
|
| 13 |
+
COPY . .
|
| 14 |
+
|
| 15 |
+
# Build the application (outputs to /app/dist)
|
| 16 |
+
RUN npm run build
|
| 17 |
+
|
| 18 |
+
# Stage 2: Serve the application using Nginx
|
| 19 |
+
FROM nginx:alpine
|
| 20 |
+
|
| 21 |
+
# Remove default nginx static assets
|
| 22 |
+
RUN rm -rf /usr/share/nginx/html/*
|
| 23 |
+
|
| 24 |
+
# Copy the built React app from the builder stage to Nginx's serve directory
|
| 25 |
+
COPY --from=builder /app/dist /usr/share/nginx/html
|
| 26 |
+
|
| 27 |
+
# Expose port 80 to the outside world
|
| 28 |
+
EXPOSE 80
|
| 29 |
+
|
| 30 |
+
# Start Nginx
|
| 31 |
+
CMD ["nginx", "-g", "daemon off;"]
|