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:

  • Docker in Automation testing
  • Creating an ng-cli container in docker not working
  • How do I expose a docker container port to another container
  • lsb_release of the host OS in a Docker
  • Vagrant: Sync folder with boot2docker box on Windows
  • Save data generated from a Python app running in Docker swarms in Mysql Database
  • 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?

  • docker ps shows empty list
  • Docker image before development or after? (Beginner)
  • running java applications in docker with jboss or tomcat server
  • Docker container files overwritten by host volume share
  • uwsgi layer blocks one particular API call from nginx
  • Tomcat with Docker
  • 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.