Reputation: 651
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.sstatic.net/Q2l2B.png
Upvotes: 20
Views: 22326
Reputation: 97
I know this comes late, but it might help someone, the below solution works for me.
{
"dns": ["1.1.1.1", "8.8.8.8"]
}
Upvotes: 5
Reputation: 1887
In my case working solution was to clean up docker image cache with
docker image prune
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
docker run -it node:lts-alpine sh
And run (it was some dependent "yorkie" package) in order to make sure that it can resolve network address and download the file.
wget https://registry.npmjs.org/yorkie/-/yorkie-2.0.0.tgz
Upvotes: 4
Reputation: 651
[RESOLVED] the problem was in network of docker, then i executed the folow command:
docker build -t cassiamani/nodeapp --network=host .
--network=host use dns from host, for me it's worked.
reference: https://www.linode.com/community/questions/19710/docker-npm-timeout-on-linode
Upvotes: 34