Docker:npm安装在代理之后 [英] Docker: npm install behind proxy

查看:190
本文介绍了Docker:npm安装在代理之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个Docker文件:

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安装步骤中,我收到此错误:

But I get this error, in npm install step:


npm信息它的工作,如果以ok npm信息结束npm@2.14.12 npm
信息使用node@v4.2.6 npm WARN package.json deployer-ui@1.0.0否
描述npm WARN包。 json deployer-ui@1.0.0没有仓库
字段。 npm WARN package.json deployer-ui@1.0.0没有README数据npm info
预安装deployer-ui@1.0.0 npm信息尝试注册表请求尝试#1
在7:09:23 AM npm http请求GET
https://registry.npmjs.org/body-parser npm信息尝试注册表
请求尝试#1在7:09:23上午npm http请求GET
https: //registry.npmjs.org/express npm info retry将重试,
上次尝试发生错误:错误:无法建立隧道套接字,
cause = write EPROTO npm info retry将重试,最后一次尝试错误:
错误:隧道插座无法建立,因为=写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 网址,而不是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 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆