1

I am using docker version 18.09.0. The image is built without errors. Upon creating container from the image, the container runs and exits immediately with exit status 0, even though I use -it option. Here is Dockerfile.

FROM node:8.15-alpine

WORKDIR /usr/src/app

COPY package*.json ./
COPY middleware middleware
COPY hfc-key-store hfc-key-store
COPY app.js ./

RUN apk --no-cache --virtual build-dependencies add \
    python \
    make \
    g++ \
    && npm install \
    && npm install -g forever

ENTRYPOINT ["forever", "start", "-l", "/logsBackEnd.txt", "--spinSleepTime", "10000", "app.js"]

Command to build image:

docker image build -t nid-api:1.0 .

Command to run container:

docker run -it  nid-api:1.0
Bukks
  • 408
  • 7
  • 16
  • Try to check the logs `docker logs --tail 500 CONTAINER` Here is a ressource https://docs.docker.com/engine/reference/commandline/logs/ – Ulrich Dohou Feb 15 '19 at 09:03
  • LOGS:: warn: --minUptime not set. Defaulting to: 1000ms info: Forever processing file: app.js – Bukks Feb 15 '19 at 10:19
  • I wouldn't use a tool to manage the process lifecycle inside the container. Just make the main container process be `./app.js`. _Once your program works_ and not before, use the [`docker run --restart` option](https://docs.docker.com/engine/reference/run/#restart-policies---restart) to have Docker do this for you. – David Maze Feb 15 '19 at 10:44

2 Answers2

0

You need to run in detach mode using -d

There are two reason I can think of for container to exit.

  1. If there is no service running inside container
  2. In case the service is running and docker is running without any deattach option.

The first case seems to be of more related to your error. But always run container in deattached mode. By default new version of docker always run in deattached mode

Also try the below as well.

Docker container will automatically stop after "docker run -d"

error404
  • 2,684
  • 2
  • 13
  • 21
0

The forever is running as a daemon inside the docker container and that may be the cause of making the container to exit immediately.

You can try to use dumb-init to start any process running in a docker container so that exit signals are handled correctly.

dumb-init enables you to simply prefix your command with dumb-init. It acts as PID 1 and immediately spawns your command as a child process, taking care to properly handle and forward signals as they are received.

dumb-init runs as PID 1, acting like a simple init system. It launches a single process and then proxies all received signals to a session rooted at that child process.

Since your actual process is no longer PID 1, when it receives signals from dumb-init, the default signal handlers will be applied, and your process will behave as you would expect. If your process dies, dumb-init will also die, taking care to clean up any other processes that might still remain.

Community
  • 1
  • 1
Exadra37
  • 11,244
  • 3
  • 43
  • 57