I’m try build image to node app, but when i execute docker build showed an error left run npm install
npm ERR! network timeout at: https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz
follow docker file content:
FROM node:13
# Create app directory
WORKDIR /usr/src/app
# 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 ci --only=production
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "node", "server.js" ]
follow my package.json
{
"name": "backend",
"version": "1.0.0",
"description": "",
"private": true,
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"keywords": [],
"author": "Bruno Cassiamani",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"config": "^3.3.1",
"consign": "^0.1.6",
"cors": "^2.8.5",
"express": "^4.17.1",
"request": "^2.88.2",
"xml2js": "^0.4.23"
}
}
OS relase: CentOS Linux release 8.1.1911 (Core)
Docker release: Docker version 19.03.8, build afacb8b
print error:
https://i.imgur.com/GxRgpEG.png
3
Answers
[RESOLVED] the problem was in network of docker, then i executed the folow command:
--network=host use dns from host, for me it's worked.
reference: https://www.linode.com/community/questions/19710/docker-npm-timeout-on-linode
In my case working solution was to clean up docker image cache with
And make sure that you can wget needed npm package inside required docker image. For example I used node:lts-alpine. So, you have to run
And run (it was some dependent "yorkie" package) in order to make sure that it can resolve network address and download the file.
I know this comes late, but it might help someone, the below solution works for me.