When pm2 is used in docker, you need to change the pm2 command to the pm2-docker command so that it can run in the foreground. And I personally feel that there is no need to use pm2 in docker. If the node process hangs, the corresponding container will also stop running, so when starting the docker container, add the restart=always parameter to automatically restart it
You need to ensure that pm2 is running in the foreground, which means that the process started in CMD or ENTRYPOINT in the dockerfile cannot run in daemon mode
You can specify the number of CPU cores to use when running a container. If you only allocate one core, there is no need to start multiple Node.js processes, because the basic scheduling unit of the CPU is a thread. Only one core means that you can run one Node.js process.
When pm2 is used in docker, you need to change the pm2 command to the pm2-docker command so that it can run in the foreground. And I personally feel that there is no need to use pm2 in docker. If the node process hangs, the corresponding container will also stop running, so when starting the docker container, add the restart=always parameter to automatically restart it
You can refer to: pm2 official website’s docker integration documentation
You need to ensure that pm2 is running in the foreground, which means that the process started in CMD or ENTRYPOINT in the dockerfile cannot run in daemon mode
You can specify the number of CPU cores to use when running a container. If you only allocate one core, there is no need to start multiple Node.js processes, because the basic scheduling unit of the CPU is a thread. Only one core means that you can run one Node.js process.