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: Container keeps on restarting again on again
  • How to use a bash script in Alpine Linux?
  • Docker port forwarding with dual network interface
  • Docker - how to set up Apache + PHP in docker-compose.yml
  • docker compose, vagrant and insecure Repository
  • How do I forward my Docker IP to the rest of the network?
  • 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 deploy Docker file to real machine
  • bitbucket docker Permission denied (publickey). fatal: Could not read from remote repository
  • How to launch an app via Docker on every Pull Request?
  • Pre Configured Environment variables in Jenkins
  • Redis Docker connection refused
  • Trying to create postgis inside docker file gives the error
  • 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.