cannot pm2 list in docker containers

I build a Docker image with Node.js and pm2. I started the container with:

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

Then I go inside the container with:

  • Concourse pending for long time before running task
  • It's possible to tie a domain to the docker container when building it?
  • Docker remote api don't restart after my computer restart
  • docker run -it bash -c 'Function from sourced file'
  • Why “Data Space Used” + “Data Space Available” != “Data Space Total” in docker?
  • TensorFlow docker dev workflow on mac
  • docker exec -it test /bin/bash

    In the container, exec the command:

    pm2 list

    And it stuck here:

    enter image description here

    P.s.: My application works well in the Docker container, if I add CMD pm2 start app.js in the Dockerfile.

  • Docker ENV command no longer valid when using docker run
  • Kubernetes - Readiness Probe execution after container started
  • FeignClient call with consul service throws connection refused in docker container
  • vnc to a docker container in vagrant
  • c#/Mono solution not building on remote Dokku server
  • “AH01071: Got error 'Unable to open primary script”: Container permissions or Symfony3 issue?
  • 2 Solutions collect form web for “cannot pm2 list in docker containers”

    If your dockerfile CMD is a pm2 command, you have you include –no-daemon arg option so pm2 runs in the foreground and so your docker container continues to run.

    An example Dockerfile CMD:

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

    Otherwise, without –no-daemon, pm2 launches as a background process and docker thinks the execution of the pm2 command is done running and stops.


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

    This is the new approach.

    Please do not use previous approaches.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.