Dockerized Node JS project getting: "command failed signal SIGTERM" error

I had a express application and I used this application in my Kubernetes cluster.

This application is auth service for my micro service architecture study.

I use Skaffold dev command for applying Kubernetes for this app.

My Dockerfile is like that:

FROM node:alpine

WORKDIR /app
COPY package.json .
RUN npm install

COPY . .

CMD ["npm", "start"]

And I run it with "Scaffold dev" command

And I getting error like that:

...
...    
Deployments stabilized in 3.752 seconds
Watching for changes...
[auth] npm notice 
[auth] npm notice New patch version of npm available! 7.5.1 -> 7.5.4
[auth] npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.5.4>
[auth] npm notice Run `npm install -g [email protected]` to update!
[auth] npm notice 
[auth] npm ERR! path /app
[auth] npm ERR! command failed
[auth] npm ERR! signal SIGTERM
[auth] npm ERR! command sh -c node server.js
[auth] 
[auth] npm ERR! A complete log of this run can be found in:
[auth] npm ERR!     /root/.npm/_logs/2021-02-19T16_46_28_956Z-debug.log

And my package.json file :

    {
  "name": "authservice",
  "version": "1.0.0",
  "description": "Auth Service",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "keywords": [
    "auth",
    "user"
  ],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcrypt": "^5.0.0",
    "body-parser": "^1.19.0",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "express-rate-limit": "^5.2.3",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "5.10.19",
    "morgan": "^1.10.0",
    "multer": "^1.4.2"
  },
  "devDependencies": {
    "nodemon": "^2.0.6"
  }
}

How can I solve this error?

Upvotes: 5

Views: 28661

Answers (2)

saipemmaka
saipemmaka

Reputation: 11

Faced similar issue. Please check the liveliness probe and readiness probe path.

Upvotes: 0

DazWilkin
DazWilkin

Reputation: 40296

I assume you're either incorrectly specifying your script in the package.json or your script is not server.js.

A minimal repro of your question works:

Using the Node.JS Getting Started guide's example with one minor tweak: https://nodejs.org/en/docs/guides/getting-started-guide/

NOTE Change const hostname = '127.0.0.1'; to const hostname = '0.0.0.0'; This is necessary to access the containerized app from the host.

Adding a package.json because you have one and to show npm start:

package.json:

{
    "name": "66281738",
    "version": "0.0.1",
    "scripts": {
        "start": "node app.js"
    }
}

NOTE I believe npm start defaults to "start": "node server.js"

Using your Dockerfile and:

QUESTION="66281738"
docker build --tag=${QUESTION} --file=./Dockerfile .
docker run --interactive --tty --publish=7777:3000 ${QUESTION}

Yields:

> [email protected] start
> node app.js

Server running at http://0.0.0.0:3000/

NOTE docker run binds the container's :3000 port to the host's :7777 just to show these need not be the same.

Then:

curl --request GET http://localhost:3000/

Yields:

Hello World

Upvotes: 2

Related Questions