【问题标题】:docker build problem with npm install Error: Invalid response body while trying to fetch https://registry.npmjs.org Socket timeoutdocker build 问题与 npm install 错误:尝试获取 https://registry.npmjs.org 时响应正文无效 套接字超时
【发布时间】:2022-02-17 16:35:53
【问题描述】:

npm install 的 docker 构建问题,它只在我测试过的 docker 内部。它在我的操作系统上完美运行

错误

Step 6/8 : RUN npm cache clear --force &&  npm install --legacy-peer-deps
 ---> Running in 361c2a07ac22
npm WARN using --force Recommended protections disabled.
npm notice 
npm notice New minor version of npm available! 8.4.1 -> 8.5.0
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.5.0>
npm notice Run `npm install -g npm@8.5.0` to update!
npm notice 
npm ERR! code ERR_SOCKET_TIMEOUT
npm ERR! errno ERR_SOCKET_TIMEOUT
npm ERR! network Invalid response body while trying to fetch https://registry.npmjs.org/styled-jsx: Socket timeout
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network '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/2022-02-17T07_12_06_500Z-debug-0.log
The command '/bin/sh -c npm cache clear --force &&  npm install --legacy-peer-deps' returned a non-zero code: 1

泊坞窗文件

FROM node:alpine

WORKDIR /app

ENV PORT 3000

COPY ./package.json /app/
COPY ./.npmrc ~

RUN npm cache clear --force &&  npm install --legacy-peer-deps

COPY . /app/

CMD ["npm", "start"]

如您所见,我添加了 .npmrc 文件,因为我在某处读过它,但它不起作用或添加 npm cache clear --force 那么我该怎么办?

【问题讨论】:

  • 也许像RUN npm cache clear --forceRUN npm install --legacy-peer-deps 这样分开两行来分别查看日志?

标签: javascript node.js docker npm


【解决方案1】:

您的应用使用的是什么版本的 Node?你的操作系统上安装了什么版本的节点?

您可以使用以下方法检查它:

node -v

您使用的这张图片node:alpine 是该节点的最新版本,目前是 17。所以也许您应该使用旧版本(您的应用中实际拥有的那个)。 你可以在Docker Hub找到正确的图片

【讨论】:

    猜你喜欢
    • 2020-08-06
    • 2020-08-12
    • 2021-01-26
    • 1970-01-01
    • 2021-10-01
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多