Should I use forever/pm2 within a (Docker) container?

牧云@^-^@ 提交于 2019-11-28 16:28:04

问题


I am refactoring a couple of node.js services. All of them used to start with forever on virtual servers, if the process crashed they just relaunch.

Now, moving to containerised and state-less application structures, I think the process should exit and the container should be restarted on a failure.

Is that correct? Are there benefits or disadvantages?


回答1:


My take is do not use an in-container process supervisor (forever, pm2) and instead use docker restart policy via the --restart=always (or one of the other flavors of that option). This is more inline with the overall docker philosophy, and should operate very similarly to in-container process supervision since docker containers start running very quickly.

The strongest advocate for running in-container process supervision I've seen is in the phusion baseimage-docker README if you want to explore the other position on this topic.




回答2:


While it's a good idea to use --restart=always as a failsafe, container restarting is relatively slow (5+ seconds with the simple Hello World Node server described here), so you can minimize app downtime using something like forever.

A downside of restarting the process within the container is that crash recovery can now happen two ways, which might have implications for your monitoring, etc.




回答3:


Node needs clustering setup if you are running on a server with multiple CPUs.

With PM2 you get that without writing any extra code. http://pm2.keymetrics.io/docs/usage/cluster-mode/

Unless you are using a bunch of servers with single CPU instances than i would say use PM2 in production.

pm2 will also be quicker to restart than docker



来源:https://stackoverflow.com/questions/28942614/should-i-use-forever-pm2-within-a-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!