Error when building a nodejs docker image - node.js

This is the Dockerfile I use to generate the image
FROM node:12.14.1
WORKDIR /usr/src/app
ADD package.json .
RUN npm install
ADD . .
EXPOSE 3000
CMD [ "npm", "run", "start" ]
This is how i build the image
sudo docker build -t digi-api .
The output i get is:
Sending build context to Docker daemon 177.2MB
Step 1/7 : FROM node:12.14.1
---> 7a73e56f893c
Step 2/7 : WORKDIR /usr/src/app
---> Using cache
---> d5b2943c4dc3
Step 3/7 : ADD package.json .
---> Using cache
---> 45ca07d61d88
Step 4/7 : RUN npm install
---> Running in 14540086976d
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! network request to https://registry.npmjs.org/#nestjs%2fcommon failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-01-20T10_17_24_065Z-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 1
I am running DEEPIN os 15.11. I have a stable internet connection and i am not on any proxy.

Related

Docker and NPM private registry

i use jetbrains space-on-permises on my pc. When i try to build a node docker image with a npm registry set in the npm registry i've a error:
this is my docker file:
# Builder stage
FROM node:18 as builder
WORKDIR /usr/src/app
COPY package.json ./
COPY snkrs-url.json ./
COPY .npmrc ./
COPY . .
RUN npm config delete proxy
RUN npm config set #sneakers-monitor:registry http://packages:8390/npm/p/sneakers-monitor/npm/
RUN npm config set //packages:8390/npm/p/sneakers-monitor/npm/:_authToken=eyJhbGciOiJSUzUxMiJ9.eyJzdWIiOiIxbjdENmoxc1Y0ZHQiLCJhdWQiOiJjaXJjbGV0LXdlYi11aSIsIm9yZ0RvbWFpbiI6ImpldGJyYWlucyIsIm5hbWUiOiJhZG1pbiIsImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDg0IiwicGVybV90b2tlbiI6IjJuWHFuRDRYRTVCTiIsInByaW5jaXBhbF90eXBlIjoiVVNFUiIsImlhdCI6MTY3MDY3Njk1Mn0.g7sOBo7r7SvNuWq7VvKttdusdMf5Vad2Als24xBuGFDBId1oGa6XG61Y6X98mE_lifvtMxydD5DFspe49lH2TyS2hhNUI2vYxMno9jcA3oWGNjXMuK8cpAEterD70aNl_yCT-bS2hTh0jeVUKtLewGvoiXIPOvrCTMnyYpHA_qmixi1Qtw49O5rnB9SzTx6Go_iHUJB1p4ZFhEvY_mH8AVFSTo00YRE-RQEQ0j3p54me9amlC5xUTRg6c3bI5J9ElqVPgKn2arODsITKtYkD3vS6K3MRUtCnrr2eKxw3LtDYH1GfXq-hCw5TlYxWiBB_z21U7tnpOCKM8GkxrH-E3hdlYwt4ychoFveDclQKCC8PsMVOWOI9oaMqVttWMz9HkgvAEB3y--pV54s_pHm6xrH_CrYL2oEZ6rELjyJDaZYB-EPpLOrRRIXOYlitYUpe8nKcz13I7HEChpT0huXiP6IWqdotvtSdnR89irqoDILH7RZbGGjkFYB6Yz04zPwzn91-CBONuTMRLm39iv880l2tU6-7BlM2Jivyx0I_IKJCqJjymE0zfXJqB9I1F1S4T2GHBALHbTXtXa9dgC-unwJN3L_4TEPxaozzzcH8ikld8GOcd3bXJX1d-iD4GjqX9ek8cidwqmRzR3ZobAVKnb7_NC0vrXxG14BTqrvJNBg
RUN npm install
RUN npm run build
RUN npm prune --production
RUN wget https://gobinaries.com/tj/node-prune --output-document - | /bin/sh && node-prune
# Runner stage
FROM node:18-alpine as runner
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/snkrs-url.json ./
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/node_modules ./node_modules
EXPOSE 5000
CMD [ "node", "dist/index.js" ]
And this is the error:
#18 188.0 npm ERR! code ENOTFOUND
#18 188.0 npm ERR! syscall getaddrinfo
#18 188.0 npm ERR! errno ENOTFOUND
#18 188.0 npm ERR! network request to http://packages:8390/npm/p/sneakers-monitor/npm/#sneakers-monitor%2fdiscord-bot failed, reason: getaddrinfo ENOTFOUND packages
#18 188.0 npm ERR! network This is a problem related to network connectivity.
#18 188.0 npm ERR! network In most cases you are behind a proxy or have bad network settings.
#18 188.0 npm ERR! network
#18 188.0 npm ERR! network If you are behind a proxy, please make sure that the
#18 188.0 npm ERR! network 'proxy' config is set properly. See: 'npm help config'
#18 188.0
Can anyone help me?

npm ERR! request to https://registry.npmjs.org during Dockerizing a Node.js web app

Hi im trying dockerizing my project in node and react, mi operative system is CentOS 8.1,version node 12.16.1 and Docker version 19.03.8. I follow the tutorial from node https://nodejs.org/fr/docs/guides/nodejs-docker-webapp/ my docker file is the next
FROM node:12
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm","start"]
and .dockerignore is
node_modules
npm-debug.log
when i build i have error in step 4 npm install
Step 4/6 : RUN npm install
---> Running in 922fd6d848a1
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org
I hope can help me, thanks for reading
if someday any have this problem you can resolve with this
docker build . --network host -t mytag ..
or another suggestion suggestion you can check the following link
https://github.com/StefanScherer/dockerfiles-windows/issues/270

Docker container that pulls from private gilab repository

I'm building a Docker container for my Node.js + Vue application.
Since I have a global css library in another repository I have added this line in my package.json file:
"lib-css": "git+ssh://git#git.lib.com:9922/username/lib-css.git#development",
That way when I run npm install I install also my CSS library. The problem is that on my local env it asks for my password and I can insert it, but in the Docker build the process fails with the following error:
Step 7/10 : RUN npm install
---> Running in db10ca83586d
npm WARN deprecated babel-preset-es2015#6.24.1: 🙌 Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git#git.lib.com:9922/username/lib-css.git
npm ERR!
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-12-11T08_49_11_152Z-debug.log
This is my current Dockerfile:
FROM node:carbon
WORKDIR /usr/src/app
RUN mkdir -p /root/.ssh
COPY .secrets /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh && chmod 600 /root/.ssh/*
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm install --only=production
# Bundle app source
COPY . .
EXPOSE 8081
CMD [ "npm", "run dev" ]
~
My .secrets file contains my private key associated to the repository.
How can I make this works?

Docker image creation throwing "no such file or directory, access '/node_modules/sails'" when dockerizing a sails.js app

Below is the Dockerfile
FROM node:latest
RUN npm install -g sails#0.12.13
ADD . / ./
RUN npm install
EXPOSE 80
CMD (sails lift)
Image creation fails with following log:
ending build context to Docker daemon 70.03MB
Step 1/6 : FROM node:latest
---> 60bea5b86079
Step 2/6 : RUN npm install -g sails#0.12.13
---> Using cache
---> 3f3c7fcdb090
Step 3/6 : ADD . / ./
---> Using cache
---> 78700b41cf26
Step 4/6 : RUN (npm install)
---> Running in d49423611a77
npm info it worked if it ends with ok
npm info using npm#5.3.0
npm info using node#v8.4.0
npm info lifecycle ecs-notification#0.0.0~preinstall: ecs-notification#0.0.0
npm WARN checkPermissions Missing write access to /node_modules/sails
npm ERR! path /node_modules/sails
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall access
npm ERR! enoent ENOENT: no such file or directory, access '/node_modules/sails'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-09-08T13_00_06_956Z-debug.log
The command '/bin/sh -c (npm install)' returned a non-zero code: 254
Even if I try to create the directory, or change the permission to 777 using:
RUN (mkdir -p /node_modules/sails; chmod 777 /node_modules/sails)
it still fails with the same error:
Sending build context to Docker daemon 70.03MB
Step 1/7 : FROM node:latest
---> 60bea5b86079
Step 2/7 : RUN npm install -g sails#0.12.13
---> Using cache
---> 3f3c7fcdb090
Step 3/7 : RUN (mkdir -p /node_modules/sails; chmod 777 /node_modules/sails)
---> Using cache
---> c7f1784c24c8
Step 4/7 : ADD . / ./
---> Using cache
---> 334017659dde
Step 5/7 : RUN (npm install)
---> Running in 833e3ef6a010
npm info it worked if it ends with ok
npm info using npm#5.3.0
npm info using node#v8.4.0
npm info lifecycle ecs-notification#0.0.0~preinstall: ecs-notification#0.0.0
npm WARN checkPermissions Missing write access to /node_modules/sails
npm ERR! path /node_modules/sails
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall access
npm ERR! enoent ENOENT: no such file or directory, access '/node_modules/sails'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-09-08T13_13_55_258Z-debug.log
The command '/bin/sh -c (npm install)' returned a non-zero code: 254
Docker version: 17.06.2-ce-mac27 (19124)
Any pointers around how I can debug this?
Change your Dockerfile to below
FROM node:latest
RUN npm install -g sails#0.12.13
WORKDIR /usr/app
COPY package.json ./
RUN npm install
COPY . ./
EXPOSE 80
CMD sails lift
You should only copy package.json first and the do npm install and then copy code. Also your ADD statement was wrong. There was an extra space
Next make sure you have .dockerignore which ignores the node_modules. Else node_modules will be overwritten by the copy operation

Docker running test with nodejs and volume

I'm learning docker and I'm having some troubles with the volume in a development environment with Nodejs.
I having the following simple dockerfile that aims to start my unit tests from a NodeJS parent image:
FROM node:4-onbuild
VOLUME ["/usr/src/app"]
CMD [ "npm", "test" ]
I'm running my container this way:
docker run -v /C/Users/myUser/dockertest:/usr/src/app notest
But I keep receiving the following error:
npm info it worked if it ends with ok
npm info using npm#2.15.9
npm info using node#v4.5.0
npm ERR! Linux 4.4.15-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "test"
npm ERR! node v4.5.0
npm ERR! npm v2.15.9
npm ERR! path /usr/src/app/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /usr/src/app/npm-debug.log
I don't understand why I'm not able to find the package.json file inside of the /usr/src/app folder inside of my container.
The fact is that if I'm using the following docker file :
FROM node:4-onbuild
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
CMD [ "npm", "test" ]
My tests will be running in the container, but only after building step (so I have to build each time I make a modification...) . I need to play these tests any time I want, by launching a docker command (restart ? exec ?) quickly
Thanks for your help
You want to COPY everything build relevant and link your codebase on containerstart.
FROM node:4.4
# Enviroment variables
ENV HOMEDIR /data
RUN mkdir -p ${HOMEDIR}
WORKDIR ${HOMEDIR}
# install all dependencies
COPY package.json ./
RUN npm install
# add node content initially
COPY . .
CMD ["npm", "test"]
And then link it on start:
version: '2'
services:
myApp:
build:
context: .
dockerfile: Dockerfile
image: "myApp"
volumes:
- .:/data
You should now be able to change your codebase without restarting/rebuilding your container.

Resources