amazon-web-servicesdockeramazon-ecspm2

Is PM2 necessary for running docker images through ECS?


We use to have PM2 in production for nodejs applications

Now comes docker which ideally expects us to have one process per container(although it got changed to one concern per container now) and then you can spawn many containers if your app is horizontally scalable.

Finally, there comes providers who manages containers, AWS ECS for example spins up machines and runs the docker containers. When it gets crashed or unreachable it spins up another machine and makes sure that the application is running if possible. Also there is a HealthCheck option in the docker itself and that is being used by AWS ECS (I assume other providers will use it as well).

So given all this, do I really need PM2 or any other process manager when running a docker image on ECS or am I missing something completely?


Solution

  • In my opinion, no - you shouldn't need to use PM2 or similar process managers for containers in ECS.

    Just stick to running a single process (i.e. node) per container, and let the ECS agent manage everything else. As you said, if it crashes and the process exits, the agent will simply replace it with another container in your cluster. For resilience, be sure to have at least 2 ECS instances in your cluster and run at least 2 containers for each app (the agent will place these across instances).

    Also use application load balancers and define HTTP health checks in your target groups, just incase the app becomes unresponsive but the process does not exit for whatever reason.