Node.js docker container exits with exit code 0 after yurn start completes successfully

1.6k views Asked by At

my Dockerfile bellow builds successfully:

FROM node:10-alpine

ENV VS_ENV prod

WORKDIR /var/www

COPY shims.d.ts ./
COPY tsconfig.json ./
COPY tsconfig-build.json ./
COPY package.json ./
COPY yarn.lock ./
COPY config ./config
COPY core ./core
COPY ecosystem.json ./
COPY .eslintignore ./
COPY .eslintrc.js ./
COPY lerna.json ./
COPY package.json ./
COPY src ./src

RUN apk add --virtual .build-deps ca-certificates wget python make g++ \
  && apk add git \
  && yarn install \
  && yarn build

and then I run the container with:

docker run -it -p 3000:3000 vue/sf:4a yarn start

logs show that the application starts as far as I understand:

[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
[PM2][WARN] Applications server not running, starting...
[PM2] App [server] launched (4 instances)
┌──────────┬────┬─────────┬─────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐
│ App name │ id │ mode    │ pid │ status │ restart │ uptime │ cpu │ mem       │ user │ watching │
├──────────┼────┼─────────┼─────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤
│ server   │ 0  │ cluster │ 52  │ online │ 0       │ 0s     │ 34% │ 72.5 MB   │ root │ disabled │
│ server   │ 1  │ cluster │ 59  │ online │ 0       │ 0s     │ 28% │ 61.0 MB   │ root │ disabled │
│ server   │ 2  │ cluster │ 70  │ online │ 0       │ 0s     │ 24% │ 35.3 MB   │ root │ disabled │
│ server   │ 3  │ cluster │ 81  │ online │ 0       │ 0s     │ 20% │ 30.0 MB   │ root │ disabled │
└──────────┴────┴─────────┴─────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app
Done in 2.08s.

but the container does not stay up as I would expect instead exits with status code 0, so no errors:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
8b77d6ffe26e        vue/sf:4            "docker-entrypoint.s…"   11 minutes ago      Exited (0) 11 minutes ago                       keen_raman

Any ideas please what am I doing wrong?

Thank you

1

There are 1 answers

0
dr0plet35 On

Your container exit status is 0, and this means everything has worked as expected. It seems that your application just start some services then exits. We need see the command which runs your application. Also, we may need to see your source code.

By the way, if the command that you run is related with pm2, try to start pm2 with --no-daemon option.