gpt4 book ai didi

docker - npm install 在构建 docker 镜像时返回连接超时

转载 作者:行者123 更新时间:2023-12-02 17:55:02 25 4
gpt4 key购买 nike

我正在尝试制作一个 docker 图像,包括 newman .我尝试使用 node:10-alpine 构建图像,但我收到连接拒绝错误 npm install -g newman .这是我的 docker 命令:

RUN set http_proxy= && \
set https_proxy= && \
yarn config delete proxy && \
npm config rm https-proxy && \
npm config rm proxy && \
npm config set registry http://registry.npmjs.org/ && \
npm config set strict-ssl false && \
npm cache clean --force && \
npm cache verify && \
npm install -g newman

完整的错误是:
npm ERR! code ECONNREFUSED
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to https://registry.npmjs.org/newman failed, reason: connect ECONNREFUSED 192.168.14.109:1087
npm ERR! at ClientRequest.req.on.err (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js:68:14)
npm ERR! at ClientRequest.emit (events.js:198:13)
npm ERR! at onerror (/usr/local/lib/node_modules/npm/node_modules/agent-base/index.js:101:9)
npm ERR! at callbackError (/usr/local/lib/node_modules/npm/node_modules/agent-base/index.js:123:5)
npm ERR! at process._tickCallback (internal/process/next_tick.js:68:7)
npm ERR! { FetchError: request to https://registry.npmjs.org/newman failed, reason: connect ECONNREFUSED 192.168.14.109:1087
npm ERR! at ClientRequest.req.on.err (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js:68:14)
npm ERR! at ClientRequest.emit (events.js:198:13)
npm ERR! at onerror (/usr/local/lib/node_modules/npm/node_modules/agent-base/index.js:101:9)
npm ERR! at callbackError (/usr/local/lib/node_modules/npm/node_modules/agent-base/index.js:123:5)
npm ERR! at process._tickCallback (internal/process/next_tick.js:68:7)
npm ERR! message:
npm ERR! 'request to https://registry.npmjs.org/newman failed, reason: connect ECONNREFUSED 192.168.14.109:1087',
npm ERR! type: 'system',
npm ERR! errno: 'ECONNREFUSED',
npm ERR! code: 'ECONNREFUSED',
npm ERR! stack:
npm ERR! 'FetchError: request to https://registry.npmjs.org/newman failed, reason: connect ECONNREFUSED 192.168.14.109:1087\n at ClientRequest.req.on.err (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js:68:14)\n at ClientRequest.emit (events.js:198:13)\n at onerror (/usr/local/lib/node_modules/npm/node_modules/agent-base/index.js:101:9)\n at callbackError (/usr/local/lib/node_modules/npm/node_modules/agent-base/index.js:123:5)\n at process._tickCallback (internal/process/next_tick.js:68:7)' }
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/2020-03-02T14_57_46_444Z-debug.log

然后我尝试从 alpine:3.8 制作我的图像这给了我存储库错误,而 apk update .这是我的第二个版本:
RUN apk update && apk add --no-cache nodejs npm
RUN npm install -g newman

完整的错误日志是:
Step 5/7 : RUN apk update && apk add --no-cache nodejs npm
---> Running in 6149b2571389
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.8/main: operation timed out
WARNING: Ignoring APKINDEX.adfa7ceb.tar.gz: No such file or directory
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.8/community: operation timed out
WARNING: Ignoring APKINDEX.efaa1f73.tar.gz: No such file or directory
2 errors; 13 distinct packages available
The command '/bin/sh -c apk update && apk add --no-cache nodejs npm' returned a non-zero code: 2

我还尝试使用 --network=host 构建图像选项;但在两个版本中都出现了相同的错误。

另外 ping dl-cdn.alpinelinux.org在我的系统上工作正常。

另外重启了docker服务, sudo systemctl restart docker ,又试了一次。再次得到相同的结果。

最佳答案

在我的情况下使用以下步骤:

  • 在主机中,我更改了主机服务器
    /etc/sysctl.conf:

  • 我加了
    net.ipv4.ip_forward=1
  • 我用

    nslookup registry.npmjs.org

  • 给我IP 104.16.25.38
  • 使用 IP 构建 Docker

  • docker build . --add-host registry.npmjs.org:104.16.25.38 -t test

    关于docker - npm install 在构建 docker 镜像时返回连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60497434/

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