Can't list pm2 in docker containers

I am building a Docker image with Node.js and pm2. I started a container with:

docker run -d --name test -p 22 myImage

      

Then I go into the container with

docker exec -it test /bin/bash

      

In the container, run the command:

pm2 list

      

And it got stuck here:

enter image description here

Ps: My application works well in a Docker container if I add CMD pm2 start app.js

to Dockerfile

.

+3


source to share


2 answers


If your dockerfile CMD is pm2, you have the -no-daemon arg option, so pm2 runs in the foreground and your docker container keeps running.

Example Dockerfile CMD:

CMD ["pm2", "start", "app.js", "--no-daemon"]

      



Otherwise, without -no-daemon, pm2 starts as a background process and docker thinks pm2 is running and stops.

See https://github.com/Unitech/PM2/issues/259

+3


source


CMD ["pm2-docker", "pm2.yaml"]

      

This is a new approach.



Please do not use the previous approaches.

+2


source







All Articles