-
Notifications
You must be signed in to change notification settings - Fork 6
/
Dockerfile.production
33 lines (25 loc) · 1.01 KB
/
Dockerfile.production
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
###multistage build
## Stage 1. build the react app
FROM node:20-alpine AS builder
WORKDIR /opt/web
COPY package.json package-lock.json ./
RUN npm install
ENV PATH="./node_modules/.bin:$PATH"
COPY . ./
RUN npm run build
##stage 2. build the production (server) environment
FROM nginx:1.23.2-alpine
# Install curl and envsubst
RUN apk --no-cache add curl
RUN apk --no-cache add bash
RUN curl -L https://github.com/a8m/envsubst/releases/download/v1.1.0/envsubst-`uname -s`-`uname -m` -o envsubst && \
chmod +x envsubst && \
mv envsubst /usr/local/bin
# Copy config file over to the template
COPY ./nginx.config /etc/nginx/nginx.template
# Set working directory to nginx folder
WORKDIR /usr/share/nginx/html
# Substitute out default.conf file with nginx.template AND start the nginx server
CMD ["/bin/sh", "-c", "envsubst < /etc/nginx/nginx.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]
# Generate React Static Build files for nginx to use
COPY --from=builder /opt/web/build /usr/share/nginx/html