我有 2 个图像节点和 nginx。但我面临的问题是我在节点上全局安装 pm2 但它在其他图像中不起作用,或者我不知道为什么它显示 pm2 未找到,或者我尝试使用 pm2-runtime 但没有任何作用。
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;"]
您正在构建器阶段安装 pm2 应用程序。
你必须发出命令: 运行 npm install -g pm2
第二阶段(FROM nginx:alpine 线之后)
...
FROM nginx:alpine
# Install Node.js and PM2 in the nginx image
RUN apk add --no-cache nodejs npm
RUN npm install pm2 -g
...
您需要在服务器上安装
pm2
。