web-dev-qa-db-ja.com

npm installは、Dockerイメージのビルド中に接続タイムアウトを返します

newmanを含むDockerイメージを作成しようとしています。 node:10-Alpineを使用してイメージをビルドしようとしましたが、npm install -g newman中に接続拒否エラーが発生しました。これは私のドッカーコマンドです:

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からイメージを作成しようとしました。これは私の2番目のバージョンです。

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=Hostoptionを使用してイメージをビルドしようとしました。しかし、両方のバージョンで同じエラーが発生しました。

さらに、ping dl-cdn.alpinelinux.orgは私のシステムで正常に動作します。

さらに、DockerサービスSudo systemctl restart dockerを再起動し、もう一度試しました。再び同じ結果を得た。

5

私の場合、この手順で動作します:

  1. ホストでは、ホストサーバーの/etc/sysctl.confを変更します。

追加した

net.ipv4.ip_forward=1
  1. 私が使う

    nslookup registry.npmjs.org

私にIP 104.16.25.38を与えてください

  1. Docker Build with IP

ドッカービルド。 --add-Host registry.npmjs.org:104.16.25.38 -t test

1

私の場合、これは以下で動作しますsingleステップ、

docker build --add-Host registry.npmjs.org:104.16.25.38 -t。

0
Martin Jesu