【发布时间】: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看看有没有代理设置?