-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
41 lines (29 loc) · 1.01 KB
/
Dockerfile
File metadata and controls
41 lines (29 loc) · 1.01 KB
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
# set base image to create the image for react
FROM node:20-alpine
# create a user with permission to run the app
# -S create system user, -G add the user to group
# This is done to aviod running app as root
RUN addgroup app && adduser -S -G app app
# set the user to run the app
USER app
# set working dir
WORKDIR /app
# copy package.json and package-lock.json to the working dir
# This is done to leverage docker cache if the dependencies is not changes docker will used cached deps
COPY package*.json ./
# sometimes the ownership of the files is changed to root
# thus the app cannot access the files throws error -> EACCESS: permissions denied
# To aviod this we change the permission to the root user
USER root
# change the ownership of the /app dir to the app user
RUN chown -R app:app .
# change the user back to the app user
USER app
# install deps
RUN npm install
# copy the rest of the files to the working directory
COPY . .
# expose port 5173
EXPOSE 5173
# command to run the app
CMD ["npm", "run", "dev"]