node.js - Docker build npm install 错误网络超时

标签 node.js docker

我正在尝试将镜像构建到 Node 应用程序,但是当我执行 docker build 时显示错误,请运行 npm install

npm 错误!网络超时:https://registry.npmjs.org/cookie/-/cookie-0.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"
  }
}

操作系统版本:CentOS Linux 版本 8.1.1911(核心)

Docker 发布:Docker 版本 19.03.8,构建 afacb8b

打印错误:
https://i.imgur.com/GxRgpEG.png

最佳答案

[已解决] 问题出在 docker 网络中,然后我执行了以下命令:

docker build -t cassiamani/nodeapp --network=host .

--network=host 使用来自主机的 dns,对我来说它有效。

引用:https://www.linode.com/community/questions/19710/docker-npm-timeout-on-linode

关于node.js - Docker build npm install 错误网络超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61760047/

相关文章:

javascript - NodeJS 和 MongoDB。 POST 请求获取 404 代码

docker - spark-submit如何在群集模式下传递--driver-class-path?

docker - 在 coreos 集群上链接 appserver docker 容器和数据库容器

docker - 为什么在Mac上安装Docker时未创建组名 “docker”?

ruby - 如何连接到 dockerized Sinatra 应用程序

docker - 通过 no-sandbox 但仍然出现错误 'Running as root without --no-sandbox is not supported.`

javascript - 无法在 Node js中使用util.format()解析mysql准备好的语句中的整数

node.js - 无法通过 socket.io 将我的 swift 应用程序连接到 node.js

javascript - 如何从javascript中的数组获取输出?

node.js - Mongoose 在测试中不会抛出 E11000 重复键错误