Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

what is the point of using pm2 and docker together?

We have been using pm2 quite successfully for running apps on our servers. We are currently moving to docker and we saw http://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/

But what is the point of actually using both together? Does not docker provide everything pm2 does?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...