gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:37:19 25 4
gpt4 key购买 nike

我在启动 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com