在代理下的dockerfile内部

Jul*_*oro 12 python proxy pip docker

我正在尝试为elasticsearch-curator构建一个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-curator \
  && rm -rf /var/cache/apk/*

USER curator

ENTRYPOINT [ "/usr/bin/curator"]
Run Code Online (Sandbox Code Playgroud)

事情是我在代理下,所以我必须建立我的形象:

docker build  --no-cache --build-arg HTTP_PROXY=http://xx.xx.xx.xx:xx -t elasticsearch-curator:5.4 .
Run Code Online (Sandbox Code Playgroud)

但是当它想要获得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/
Run Code Online (Sandbox Code Playgroud)

我找到了解决插入问题的人

ENV http_proxy http://proxy-chain.xxx.com:911/
ENV https_proxy http://proxy-chain.xxx.com:912/
Run Code Online (Sandbox Code Playgroud)

在Dockerfile中,但我不可能,因为我的代理仅在我的建筑物上有效,所以如果来自其他地方的另一个人想要构建图像,他将需要从Dockerfile中删除http_proxy env var.

有没有其他方法可以实现它?这似乎是一个非常常见的用例......

Jul*_*oro 18

我通过添加HTTPS_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 .
Run Code Online (Sandbox Code Playgroud)


yam*_*enk 7

不要在Dockerfile中包含代理设置。

如果您已在主机上正确配置了代理设置,则可以使用构建Docker映像--network= host。这将使build命令使用主机的网络设置。

docker build  --no-cache --network=host -t elasticsearch-curator:5.4 .
Run Code Online (Sandbox Code Playgroud)