Launch two nodejs app inside Docker container using pm2

Jér*_*ôme 4 node.js docker pm2 dockerfile

I'm trying to launch 2 nodejs app inside a Docker container using PM2, so I made a custom Dockerfile with all the projects config

FROM node:argon

RUN npm install pm2 -g --silent

VOLUME ./src/app:/usr/src/app
WORKDIR /usr/src/app

RUN git clone https://github.com/yoonic/atlas.git backend
RUN cd backend && \
    npm i --silent && \
    pm2 start npm --name "backend" -- run dev --no-daemon

RUN git clone https://github.com/yoonic/nicistore.git frontend
RUN cd frontend && \
    npm i --silent && \
    sed -i "s#api.atlas.baseUrl#http://localhost:8000/v1#" config/client/development.js && \
    pm2 start npm --name "frontend" -- run dev --no-daemon
Run Code Online (Sandbox Code Playgroud)

I start this container with docker-compose up with this config

# NodeJS
nodejs:
  build: docker/nodejs
  container_name: nodejs
  ports:
    - 53000:3000
    - 54000:4000
Run Code Online (Sandbox Code Playgroud)

When all the container is set up, I get the PM2 process list in my terminal then docker-compose start all my containers but I the nodejs one fail instantly

nodejs exited with code 0

我的 Nodejs 应用程序正在我的容器内运行,但这个应用程序立即退出......

这是使这项工作正常进行的正确方法吗?也许不需要PM2?

我怎样才能让它发挥作用?

编辑

当我不使用时容器退出,--no-daemon因为它认为一切都已完成。但是当我使用时,--no-daemon构建过程永远不会完成,因为它显示了 Nodejs 应用程序日志

Uni*_*ech 5

使用进程文件来管理这两个应用程序:http://pm2.keymetrics.io/docs/usage/application-declaration/

例如 - process.yml:

apps:
  - script : 'npm'
    args   : 'run dev'
    cwd    : './backend'
    name   : 'backend'
  - script : 'npm'
    args   : 'run dev'
    cwd    : './frontend'
    name   : 'frontend'
Run Code Online (Sandbox Code Playgroud)

然后在 Dockerfile 中:

CMD ['pm2-docker', 'process.yml']
Run Code Online (Sandbox Code Playgroud)

有关 PM2/Docker 集成的文档:http://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/