-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
50 lines (35 loc) · 1.18 KB
/
Dockerfile
File metadata and controls
50 lines (35 loc) · 1.18 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
# Base image for Node.js and Yarn
FROM node:18 as builder
# Set working directory
WORKDIR /usr/src/app
# Copy backends into the image
COPY ./app1 ./app1
COPY ./app2 ./app2
# Install dependencies and build app1
WORKDIR /usr/src/app/app1
RUN npm install
# Install dependencies and build app2
WORKDIR /usr/src/app/app2
RUN npm install
# Final image: Nginx + PM2 + Backends
FROM nginx:latest
# Copy Nginx configuration
COPY nginx/nginx.conf /etc/nginx/nginx.conf
# Install Node.js and PM2
RUN apt-get update && apt-get install -y curl && \
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs && \
npm install -g pm2
# Copy backends from the builder stage
COPY --from=builder /usr/src/app /usr/src/app
# Set working directory for PM2
WORKDIR /usr/src/app
# Expose ports for Nginx
EXPOSE 80
# Start Nginx and both backends
CMD pm2 start /usr/src/app/app1/index.js --name app1 && \
pm2 start /usr/src/app/app2/index.js --name app2 && \
nginx -g "daemon off;"
# ////
# COPY default.conf /etc/nginx/conf.d/default.conf
# CMD /bin/bash -c "envsubst '\$PORT' < /etc/nginx/conf.d/default.conf > /etc/nginx/conf.d/default.conf" && nginx -g 'daemon off;'