1
- # This file is the main docker file configurations
1
+ # Stage 1 - the build process
2
+ # FROM node:14-alpine as build
2
3
3
- # Official Node JS runtime as a parent image
4
- FROM node:10.16.0-alpine
4
+ FROM node:14-alpine as build-stage
5
5
6
- # Set the working directory to ./app
7
- WORKDIR /app
6
+ # set working directory
7
+ RUN mkdir /usr/app
8
+ # copy all files from current directory to docker
9
+ COPY . /usr/app
8
10
9
- # Install app dependencies
10
- # A wildcard is used to ensure both package.json AND package-lock.json are copied
11
- # where available (npm@5+)
12
- COPY package.json ./
11
+ WORKDIR /usr/app
13
12
14
- RUN apk add --no-cache git
13
+ # Remove package-lock.json
14
+ RUN rm ./package-lock.json
15
15
16
- # Install any needed packages
16
+ # install and cache app dependencies
17
17
RUN npm install
18
18
19
- # Audit fix npm packages
20
- RUN npm audit fix
19
+ # add `/usr/src/app/node_modules/.bin` to $PATH
20
+ ENV PATH /usr/src/app/node_modules/.bin:$PATH
21
21
22
- # Bundle app source
23
- COPY . /app
22
+ RUN npm run build
24
23
25
- # Make port 3000 available to the world outside this container
26
- EXPOSE 3000
24
+ # Stage 2
25
+ # Copy the react app build above in nginx
26
+ FROM nginx:alpine
27
27
28
- # Run app.js when the container launches
29
- CMD ["npm" , "start" ]
28
+ # Set working directory to nginx asset directory
29
+ WORKDIR /usr/share/nginx/html
30
+
31
+ # Remove default nginx static assets
32
+ RUN rm -rf ./*
33
+
34
+ # Copy static assets from builder stage
35
+ COPY --from=build-stage /usr/app/build .
36
+ COPY nginx.conf /etc/nginx/conf.d/default.conf
37
+
38
+ # Containers run nginx with global directives and daemon off
39
+ ENTRYPOINT ["nginx" , "-g" , "daemon off;" ]
0 commit comments