I have 2 images node and nginx. But issue I am facing is I install pm2 on node globally but its not working in other image or i dont know why its showing pm2 not found or I try with pm2-runtime but not working anything.
FROM node:14.21.3 AS builder
WORKDIR /app
COPY package.json ./
RUN npm i [email protected]
RUN npm install -g @angular/[email protected]
RUN yarn install --ignore-engines
RUN npm install -g pm2
# Copy the entire project directory into the container
COPY . .
# Build both frontend and backend
RUN yarn build-docker
FROM nginx:alpine
# Copy built Angular app from the builder stage to the NGINX HTML directory
COPY --from=builder /app/dist/client /usr/share/nginx/html
# Copy built Node.js backend
COPY --from=builder /app/dist /app/dist
# Expose port 80 for frontend and port 9000 for backend
EXPOSE 80
EXPOSE 9100
# Start both Angular frontend and Node.js backend using PM2
CMD ["pm2", "start", "/app/dist/index.js", "--", "nginx", "-g", "daemon off;"]
2
Answers
you are installing the pm2 application in the builder stage.
you have to give the command:
RUN npm install -g pm2
in the second stage (after the FROM nginx:alpine line)
You need to install
pm2
on the server.