-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
41 lines (31 loc) · 982 Bytes
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Use Node.js as base image for building the app
FROM node:latest AS builder
# Set working directory
WORKDIR /app
# Copy package.json and package-lock.json to the working directory
COPY package.json package-lock.json ./
# Install dependencies
RUN npm install
# Copy the entire project to the working directory
COPY . .
# Build the app
RUN npm run build
# Use NGINX as a lightweight server to serve the built React app
FROM nginx:latest
# Overwrite NGINX default configuration with custom configuration to handle React Router routing
RUN echo ' \
server { \
listen 80; \
server_name localhost; \
root /usr/share/nginx/html; \
index index.html; \
location / { \
try_files $uri /index.html; \
} \
}' > /etc/nginx/conf.d/default.conf
# Copy the built app from the builder stage to NGINX web server directory
COPY --from=builder /app/build /usr/share/nginx/html
# Expose port 80
EXPOSE 80
# Start NGINX server
CMD ["nginx", "-g", "daemon off;"]