-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.prod
More file actions
56 lines (41 loc) · 1.39 KB
/
Copy pathDockerfile.prod
File metadata and controls
56 lines (41 loc) · 1.39 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# production Dockerfile
FROM node:18-alpine AS base
# set working directory
WORKDIR /app
# copy package files
COPY client/package*.json ./client/
COPY server/package*.json ./server/
# install all dependencies (including dev dependencies for building)
RUN npm ci --prefix ./client && npm ci --prefix ./server
# copy source code
COPY client/ ./client/
COPY server/ ./server/
# build client for production
RUN cd client && npm run build
# remove dev dependencies to reduce image size
RUN cd client && npm prune --production
RUN cd server && npm prune --production
# production stage
FROM node:18-alpine AS production
# install nginx and create necessary directories
RUN apk add --no-cache nginx && \
mkdir -p /etc/nginx/ssl /var/log/nginx /var/cache/nginx /run/nginx /var/lib/nginx/tmp
# set working directory
WORKDIR /app
# copy built client files
COPY --from=base /app/client/dist /usr/share/nginx/html
# copy server files and node_modules
COPY --from=base /app/server /app/server
COPY --from=base /app/server/node_modules /app/server/node_modules
# copy nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# create startup script
RUN echo '#!/bin/sh' > /start.sh && \
echo 'nginx' >> /start.sh && \
echo 'cd /app/server' >> /start.sh && \
echo 'exec node server.js' >> /start.sh && \
chmod +x /start.sh
# expose ports
EXPOSE 80 443
# start nginx and server as root
CMD ["/start.sh"]