Python 代理下dockerfile内部的Pip
我正试图为elasticsearch馆长打造一个Docker形象 以下是dockerfile:Python 代理下dockerfile内部的Pip,python,docker,proxy,pip,Python,Docker,Proxy,Pip,我正试图为elasticsearch馆长打造一个Docker形象 以下是dockerfile: FROM alpine:3.7 RUN adduser -S curator RUN apk add --update \ python \ python-dev \ py-pip \ build-base \ && pip install virtualenv \ && pip install elasticsearch-c
FROM alpine:3.7
RUN adduser -S curator
RUN apk add --update \
python \
python-dev \
py-pip \
build-base \
&& pip install virtualenv \
&& pip install elasticsearch-curator \
&& rm -rf /var/cache/apk/*
USER curator
ENTRYPOINT [ "/usr/bin/curator"]
事实上,我受委托,所以我必须通过以下方式建立我的形象:
docker build --no-cache --build-arg HTTP_PROXY=http://xx.xx.xx.xx:xx -t elasticsearch-curator:5.4 .
但当它想要获得virtualenv时,我得到:
Collecting virtualenv
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb8259ed350>, 'Connection to pypi.python.org timed out. (connect timeout=15)')': /simple/virtualenv/
Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb8259ed210>, 'Connection to pypi.python.org timed out. (connect timeout=15)')': /simple/virtualenv/
在Dockerfile中,但这对我来说是不可能的,因为我的代理仅在我的建筑上有效,因此如果来自其他地方的其他人想要构建映像,他将需要从Dockerfile中删除http_proxy env var
有没有其他方法可以实现这一目标?这似乎是一个非常常见的用例…我认为这是因为pip安装需要显式的代理参数 尝试对pip安装进行
install.sh
如果配置了代理(作为build arg
传递,即在环境中设置),请使用以下工具安装它:
pip install --proxy=https://user@mydomain:port virtualenv
使用env变量:
pip install --proxy=$HTTP_PROXY virtualenv
如果没有,请在不使用代理的情况下安装pip。我通过在命令行中添加
HTTPS\u proxy
解决了这个问题:
docker build --no-cache --build-arg HTTP_PROXY=http://xx.xx.xx.xx:xx --build-arg HTTPS_PROXY=http://xx.xx.xx.xx:xx -t elasticsearch-curator:5.4 .
不要在Dockerfile中包含代理设置 如果已在主机上正确配置代理设置,则可以使用
--network=host
构建docker映像。这将使build命令使用主机的网络设置
docker build --no-cache --network=host -t elasticsearch-curator:5.4 .
您可以通过主目录或用户目录中的~\.docker\config.json文件配置所有客户端代理:
{
"credsStore": "wincred",
"auths": {},
"stackOrchestrator": "swarm",
"proxies":
{
"default":
{
"httpProxy": "http://127.0.0.1:3001",
"noProxy": "*.test.example.com,.example2.com"
}
}
}
默认情况下,前三个条目存在,只需将“代理”部分添加到文件中即可
来源:解决方案应该已经完成了这个技巧。您的主机是windows还是linux?是否在代理中设置了一些用户/paswd?在这种情况下,ard应该是http\u代理=http://USERNAME:PASSWORD@my proxy.com:3128/nop,我不使用login/pass。build args正在加载alpine映像,但它不适用于pip:(我没有测试它,我在命令行中找到了解决方案,但即使它能工作,我也不想在Dockerfile中编写代理变量,我更喜欢纯命令行。无论如何,感谢您的帮助!我明白了……这只是为了通过https代理:-P。这为我完成了任务。我无法在没有--network=hostWorks和“FROM python:3.7”的情况下安装flask
{
"credsStore": "wincred",
"auths": {},
"stackOrchestrator": "swarm",
"proxies":
{
"default":
{
"httpProxy": "http://127.0.0.1:3001",
"noProxy": "*.test.example.com,.example2.com"
}
}
}