Docker build npm安装错误网络超时
我正在尝试将映像构建到节点应用程序,但是当我执行docker build时显示了一个错误,请运行npm install
npm错误!网络超时位于:.4.0.tgz
跟随docker文件内容:
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" ]
关注我的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版本:CentOS Linux版本8.1.1911(核心)
Docker版本:Docker版本19.03.8,构建afacb8b
打印错误:.png
回答如下:[已解决]问题出在docker网络中,然后我执行了以下命令:
docker build -t cassiamani/nodeapp --network=host .
-network = host使用来自主机的dns,对我来说这是有效的。
参考:https://www.linode/community/questions/19710/docker-npm-timeout-on-linode