NodeJS + Forever + Docker configuration doesn't work

I have a following Dockerfile:

FROM    debian:stable

RUN      apt-get update && apt-get upgrade -y
RUN      apt-get install -y curl
RUN      curl -sL | bash -
RUN      apt-get install -y nodejs
RUN      npm install forever -g

# App
ADD . /api
# Install app dependencies
RUN cd /api; npm install

EXPOSE  8080
CMD ["forever", "start", "/api/index.js", "8080"]

When I try to run docker run -p 8080:8080 my-app@1.0.0 I get the following message:

  • IBM Containers (Dockers) service in Bluemix start before network service is ready
  • Gulp build into Docker container when NODE_ENV=production
  • Unable to remove tag of a docker image due to 'no such image' error
  • How can I edit files in a docker container when it's down/not-started
  • Can a single docker host be managed by multiple docker-machine instances?
  • Yesod scaffolded site browserId TlsException
  • warn: –minUptime not set. Defaulting to: 1000ms

    warn: –spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms

    info: Forever processing file: /api/index.js

    and docker container stops.

    What do I need to do to container work?

  • How to start many docker-compose services with different client configs?
  • How to start Docker containers on boot, managed with Ansible (Tower)
  • Docker windows loading kernel modules
  • Jenkins and Docker
  • DockerHub set tag alias in automated build
  • Docker host information and cluster
  • One Solution collect form web for “NodeJS + Forever + Docker configuration doesn't work”

    Docker exits as soon as the given command is finished. forever start SCRIPT is starting the script as a daemon in the background, and then exiting. That’s why your container stops.

    To make it work, you should start forever in the foreground by using forever SCRIPT. The CMD in your Dockerfile should be:

    CMD ["forever", "/api/index.js", "8080"]
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.