Usually there is no point in using pm2 inside of a docker.
Both PM2 and Docker are process managers and they both can do log forwarding, restart crashed workers and many other things. If you run pm2 inside of a docker container you will hide potential issues with your service, at least following:
1) If you run a single process per container with pm2 you will not gain much except for increased memory consumption. Restarts can be done with pure docker with a restart policy. Other docker based environments (like ECS or Kubernetes) can also do it.
2) If you run multiple processes you will make monitoring harder. CPU/Memory metrics are no longer directly available to your enclosing environment.
3) Health checks requests for a single PM2 process will be distributed across workers which is likely to hide unhealthy targets
4) Worker crashes are hidden by pm2. You will hardly ever know about them from your monitoring system (like CloudWatch).
5) Load balancing becomes more complicated since you're virtually going to have multiple levels of load balancing.
Also running multiple processes inside of a docker container contradicts the philosophy of docker to keep a single process per container.
One scenario I can think of is if you have very limited control over your docker environment. In this case running pm2 may be the only option to have control over worker scheduling.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…