-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
62 lines (43 loc) · 1.64 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# STAGE 1
# A Dockerfile is a configuration file that defines the image for your Docker container.
# In your React project directory, create a file named Dockerfile (without any file extension) and add the following content:
# Use an official Node.js runtime as the base image
FROM node:18 as BUILD_IMAGE
# Set the working directory inside the container
WORKDIR /app
# Copy package.json and package-lock.json to the container
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application code to the container
COPY . .
# Create a production build of our application
RUN npm run build
# Use Nginx as the production server
FROM nginx:1-alpine-slim
# Copy the built React app to Nginx's web server directory
COPY --from=BUILD_IMAGE /app/dist /usr/share/nginx/html
# Expose port 80 for the Nginx server
EXPOSE 80
# Start Nginx when the container runs
CMD ["nginx", "-g", "daemon off;"]
# # Multi-stage build reduces size and does not expose code in our container
# # STAGE 2
# FROM node:18-alpine as PRODUCTION_IMAGE
# WORKDIR /app
# COPY --from=BUILD_IMAGE /app/dist/ /app/dist/
# RUN npm install -g vite
# # Expose a port (e.g., 8080) for the application
# EXPOSE 8080
# COPY package*.json ./
# COPY vite.config.js .
# # Start the React app when the container runs
# CMD [ "npm", "run", "preview" ]
# # In order to build an image from a Dockerfile, run the following command:
# # docker build . -t "website:v2"
# #
# # Check the list of available docker images on our local system by running the following command:
# # docker images
# #
# # Run the following command to spin up a container:
# # docker run -p 8080:8080 website:v2