node.js - docker build 在 npm install 上失败,原因 : connect ECONNREFUSED 104. 16.17.35:443

标签 node.js docker ubuntu

我在启动 Docker 容器时遇到了一个难题,它在控制台中显示了一些奇怪的错误,因为我是新手,所以对此的线索为零:
Dockerfile:

FROM node:14

WORKDIR /usr/src/app/

COPY package.json package.json
COPY server.js server.js

RUN ping -c 4 google.com
RUN  npm config set registry https://registry.npmjs.com/
RUN echo "${http_proxy}" && echo "${HTTP_PROXY}" 

RUN npm install
# COPY . .

EXPOSE 3000

CMD ['npm', 'start']
当我运行 docker build 命令时
$ docker build -t myapp .
我得到的错误:
Sending build context to Docker daemon  947.7kB
Step 1/7 : FROM node:14
 ---> 7bef16bb2cf1
Step 2/7 : WORKDIR /usr/src/app/
 ---> Using cache
 ---> 90402606c386
Step 3/7 : COPY package.json ./
 ---> Using cache
 ---> b839b81ee876
Step 4/7 : RUN npm install
 ---> Running in 64378581f715
npm ERR! code ECONNREFUSED
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to https://registry.npmjs.org/@slack%2fevents-api failed, reason: connect ECONNREFUSED 104.16.18.35:443
npm ERR!     at ClientRequest.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js:68:14)
npm ERR!     at ClientRequest.emit (events.js:315:20)
npm ERR!     at TLSSocket.socketErrorListener (_http_client.js:469:9)
npm ERR!     at TLSSocket.emit (events.js:315:20)
npm ERR!     at emitErrorNT (internal/streams/destroy.js:106:8)
npm ERR!     at emitErrorCloseNT (internal/streams/destroy.js:74:3)
npm ERR!     at processTicksAndRejections (internal/process/task_queues.js:80:21)
npm ERR!  FetchError: request to https://registry.npmjs.org/@slack%2fevents-api failed, reason: connect ECONNREFUSED 104.16.18.35:443
npm ERR!     at ClientRequest.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js:68:14)
npm ERR!     at ClientRequest.emit (events.js:315:20)
npm ERR!     at TLSSocket.socketErrorListener (_http_client.js:469:9)
npm ERR!     at TLSSocket.emit (events.js:315:20)
npm ERR!     at emitErrorNT (internal/streams/destroy.js:106:8)
npm ERR!     at emitErrorCloseNT (internal/streams/destroy.js:74:3)
npm ERR!     at processTicksAndRejections (internal/process/task_queues.js:80:21) {
npm ERR!   type: 'system',
npm ERR!   errno: 'ECONNREFUSED',
npm ERR!   code: 'ECONNREFUSED'
npm ERR! }
npm ERR! 
npm ERR! If you are behind a proxy, please make sure that the
npm ERR! '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/2021-03-02T08_20_08_546Z-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 1
我在 Ubuntu 20.4 上,它只是一个带有 server.js 文件的简单 Node 应用程序。让我知道您是否需要我提供其他任何东西来修复它。预先感谢您的帮助!
/image/Nl7g1.png

最佳答案

docker 网络、代理或防火墙似乎有问题。它可以通过指定 --network="host" 来修复

$ docker build -t myapp . --network="host"
繁荣它开始像魅力一样工作!

关于node.js - docker build 在 npm install 上失败,原因 : connect ECONNREFUSED 104. 16.17.35:443,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66438759/

相关文章:

c++ - 阻塞串口读取

mysql - Node.Js - mysql 连接没有输出

javascript - 无法访问请求 NodeJS 中的自定义值

javascript - CanvasJS 图表 axisX 未定义

node.js - Docker,无法启动服务 : Failed to start a new language worker for runtime: node. Apple M1 有问题吗?

python - 使用rpdb远程调试Python服务器

ubuntu - apt-get 如何知道如何下载 ElasticSearch?

mysql - 如何在 javascript (nodejs) 中使用 for 或 foreach 将带有对象值的数组插入到 mysql 中?

Azure:在 Azure Web 应用程序的 Linux 容器中运行非 Web 应用程序

c - 如何在ubuntu中将c程序设置为守护进程?