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 npm@7.5.4` 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?
I guess you are specifying your script incorrectly in the package.json or your script is not server.js .
A minimal reproduction of your question works:
Using the Node.JS getting started guide example with a minor tweak: https://nodejs.org/en/docs/guides/getting-started-guide/
NOTE Change
const hostname = '127.0.0.1';toconst hostname = '0.0.0.0';This is required to access the containerized application from the host.
Add a package.json because you have one and display npm start :
package.json :
{ "name": "66281738", "version": "0.0.1", "scripts": { "start": "node app.js" } }NOTE I think
npm startdefaults 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:
> 66281738@0.0.1 start > node app.js Server running at http://0.0.0.0:3000/NOTE
docker runbinds container port:3000to host:7777just to show that they don't need to be the same.
So:
curl --request GET http://localhost:3000/Yields:
Hello World