Znfeoqm commited on
Commit
d91f619
·
verified ·
1 Parent(s): 5732426

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -1
Dockerfile CHANGED
@@ -1,20 +1,39 @@
1
  # Stage 1: Build the React application
 
2
  FROM node:18-alpine as builder
3
 
 
4
  WORKDIR /app
5
 
 
 
6
  COPY package*.json ./
 
 
7
  RUN npm install
8
 
 
9
  COPY . .
 
 
 
10
  RUN npm run build
11
 
12
  # Stage 2: Serve the application with Nginx
 
13
  FROM nginx:alpine
14
 
15
- # Copy the built React app from the builder stage
 
16
  COPY --from=builder /app/dist /usr/share/nginx/html
17
 
 
 
 
 
 
18
  EXPOSE 80
19
 
 
 
20
  CMD ["nginx", "-g", "daemon off;"]
 
1
  # Stage 1: Build the React application
2
+ # Uses a Node.js image to build the React application.
3
  FROM node:18-alpine as builder
4
 
5
+ # Set the working directory inside the container.
6
  WORKDIR /app
7
 
8
+ # Copy package.json and package-lock.json first to leverage Docker's layer caching.
9
+ # This means npm install won't re-run if these files haven't changed.
10
  COPY package*.json ./
11
+
12
+ # Install project dependencies.
13
  RUN npm install
14
 
15
+ # Copy the rest of the application source code.
16
  COPY . .
17
+
18
+ # Build the React application for production.
19
+ # Vite (used by your project) outputs to the 'dist' folder by default.
20
  RUN npm run build
21
 
22
  # Stage 2: Serve the application with Nginx
23
+ # Uses a lightweight Nginx image to serve the static files.
24
  FROM nginx:alpine
25
 
26
+ # Copy the built React application (from the 'dist' folder in the 'builder' stage)
27
+ # to Nginx's default web serving directory.
28
  COPY --from=builder /app/dist /usr/share/nginx/html
29
 
30
+ # Copy the custom Nginx configuration file.
31
+ # This file contains settings to resolve permission issues for Nginx's temporary files.
32
+ COPY nginx.conf /etc/nginx/nginx.conf
33
+
34
+ # Expose port 80, which is the default HTTP port Nginx listens on.
35
  EXPOSE 80
36
 
37
+ # Command to start Nginx in the foreground.
38
+ # 'daemon off;' ensures Nginx runs in the foreground so Docker keeps the container alive.
39
  CMD ["nginx", "-g", "daemon off;"]