【问题标题】:Building react app with docker while getting error at run npm install使用 docker 构建反应应用程序,同时在运行 npm install 时出错
【发布时间】:2021-09-17 23:30:12
【问题描述】:

我正在使用 docker 构建一个 react 应用程序,但在 RUN npm install 时出现错误。我已经添加了ENV PATH和ENV CI,但是问题还没有解决。

这是我的 docker 文件:

FROM node:alpine

ENV PATH /app/node_modules/.bin:$PATH
ENV CI=true

WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
RUN npm install
COPY ./ ./

CMD ["npm", "start"]

Docker 命令: docker build -t dockeruser/client .

终端响应:

[+] Building 213.3s (9/10)
 => [internal] load build definition from Dockerfile                                                                                                         0.0s 
 => => transferring dockerfile: 225B                                                                                                                         0.0s 
 => [internal] load .dockerignore                                                                                                                            0.0s 
 => => transferring context: 34B                                                                                                                             0.0s 
 => [internal] load metadata for docker.io/library/node:alpine                                                                                               0.0s 
 => [1/6] FROM docker.io/library/node:alpine                                                                                                                 0.0s 
 => [internal] load build context                                                                                                                            0.0s 
 => => transferring context: 957B                                                                                                                            0.0s 
 => CACHED [2/6] WORKDIR /app                                                                                                                                0.0s 
 => CACHED [3/6] COPY package.json ./                                                                                                                        0.0s 
 => CACHED [4/6] COPY package-lock.json ./                                                                                                                   0.0s 
 => ERROR [5/6] RUN npm install                                                                                                                            213.2s 
------
 > [5/6] RUN npm install:
#9 213.1 npm ERR! code ECONNRESET
#9 213.1 npm ERR! network aborted
#9 213.1 npm ERR! network This is a problem related to network connectivity.
#9 213.1 npm ERR! network In most cases you are behind a proxy or have bad network settings.
#9 213.1 npm ERR! network
#9 213.1 npm ERR! network If you are behind a proxy, please make sure that the
#9 213.1 npm ERR! network 'proxy' config is set properly.  See: 'npm help config'
#9 213.1
#9 213.1 npm ERR! A complete log of this run can be found in:
#9 213.1 npm ERR!     /root/.npm/_logs/2021-07-07T07_40_20_529Z-debug.log
------
executor failed running [/bin/sh -c npm install]: exit code: 1

【问题讨论】:

  • 你能不能试试运行这些npm config set proxy http://10.50.225.222:3128npm config set https-proxy http://10.50.225.222:3128当然要改地址和端口
  • 或者可以运行npm config list看看有没有代理设置?

标签: reactjs docker npm


【解决方案1】:

显然,您的网络没有问题,但应用程序位于代理后面,如错误日志中所示。我能想到两个可能的修复方法。

首先,您可以设置代理配置

npm config set proxy http://proxy_host:port
npm config set https-proxy https://proxy.company.com:8080

或者其次,您可以清除您的代理

npm config rm proxy
npm config rm https-proxy

set HTTP_PROXY=null
set HTTPS_PROXY=null

然后就可以运行了

npm config list

查看是否有任何代理配置。

当然,我假设你知道你的代理地址是什么。

【讨论】:

  • 是的,我已经检查了我的电脑设置,确实没有设置代理。
  • 我仍然遇到同样的错误!你能建议任何具体的解决方案来解决 npm install 错误吗?
  • 你试过在dockerfile中运行上面的命令吗?
  • 是的。它在同一点显示相同的错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-03
  • 2018-07-10
  • 2017-10-22
  • 2020-08-03
  • 1970-01-01
  • 2021-03-28
  • 1970-01-01
相关资源
最近更新 更多