Docker:在代理后面安装 npm [英] Docker: npm install behind proxy
问题描述
我有这个 Dockerfile:
I have this Dockerfile:
FROM node:argon
ENV http_proxy http://user:pass@proxy.company.priv:3128
ENV https_proxy https://user:pass@proxy.company.priv:3128
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 8080
CMD [ "npm", "start" ]
但是我在 npm install 步骤中收到此错误:
But I get this error, in npm install step:
npm info 如果它使用 npm@2.14.12 npm 以 ok npm info 结尾,它就起作用了信息使用 node@v4.2.6 npm WARN package.json deployer-ui@1.0.0 否描述 npm WARN package.json deployer-ui@1.0.0 无存储库场地.npm WARN package.json deployer-ui@1.0.0 没有 README 数据 npm 信息预安装 deployer-ui@1.0.0 npm info 尝试注册请求尝试 #1在 7:09:23 AM npm http 请求 GEThttps://registry.npmjs.org/body-parser npm 信息尝试注册request try #1 at 7:09:23 AM npm http request GEThttps://registry.npmjs.org/express npm info retry 将重试,出错最后一次尝试:错误:无法建立隧道套接字,cause=write EPROTO npm info retry 将重试,最后一次尝试出错:错误:无法建立隧道套接字,cause=write EPROTO
npm info it worked if it ends with ok npm info using npm@2.14.12 npm info using node@v4.2.6 npm WARN package.json deployer-ui@1.0.0 No description npm WARN package.json deployer-ui@1.0.0 No repository field. npm WARN package.json deployer-ui@1.0.0 No README data npm info preinstall deployer-ui@1.0.0 npm info attempt registry request try #1 at 7:09:23 AM npm http request GET https://registry.npmjs.org/body-parser npm info attempt registry request try #1 at 7:09:23 AM npm http request GET https://registry.npmjs.org/express npm info retry will retry, error on last attempt: Error: tunneling socket could not be established, cause=write EPROTO npm info retry will retry, error on last attempt: Error: tunneling socket could not be established, cause=write EPROTO
我猜是因为代理.我也试过把
I guess it is due to the proxy. I have also tried to put
RUN npm config set proxy http://user:pass@proxy.company.priv:3128
RUN npm config set https-proxy http://user:pass@proxy.company.priv:3128
但仍然出现相同的错误.
but still getting the same error.
此外,在我的文件 /etc/systemd/system/docker.service.d/http-proxy.conf 中,我有这个:
Moreover, in my file /etc/systemd/system/docker.service.d/http-proxy.conf I have this:
Environment="HTTP_PROXY=http://user:pass@proxy.company.priv:3128"
Environment="HTTPS_PROXY=https://user:pass@proxy.company.priv:3128"
提前致谢.
推荐答案
首先 https_proxy
应该使用 http url,而不是 https url.
First the https_proxy
should use an http url, not an https url.
其次,您不需要在 Dockfile 中嵌入代理设置:您可以使用 构建时间变量
Second, you don't need to embed your proxy settings in your Dockfile: you can use build time variables
docker build --build-arg HTTP_PROXY=http://user:pass@proxy.company.priv:3128 --build-arg HTTPS_PROXY=http://user:pass@proxy.company.priv:3128 .
最后,docker 服务级别的代理设置允许 docker 守护进程从互联网上拉取图像.这并不意味着 docker build
执行的 unix 命令(RUN
指令)会从中受益.因此需要将它们作为构建时环境变量传递.
Finally, proxy settings at the docker service level allows the docker daemon to pull images from internet. It does not mean the unix command executed (RUN
directive) by docker build
would benefit from them. Hence the need to pass them as build-time environment variables.
这篇关于Docker:在代理后面安装 npm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!