skip to Main Content

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


  1. 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)

    Login or Signup to reply.
  2. ...
    
    FROM nginx:alpine
    
    # Install Node.js and PM2 in the nginx image
    RUN apk add --no-cache nodejs npm
    RUN npm install pm2 -g
    ...
    
    

    You need to install pm2 on the server.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search