Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pip inside dockerfile under proxy

I am trying to build a Docker image for elasticsearch-curator,

Here is the 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"]

Thing is I am under a proxy, so I must build my image with:

docker build  --no-cache --build-arg HTTP_PROXY=http://xx.xx.xx.xx:xx -t elasticsearch-curator:5.4 .

But when it wants to get virtualenv, I get:

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/

I found people solving issue inserting

ENV http_proxy http://proxy-chain.xxx.com:911/
ENV https_proxy http://proxy-chain.xxx.com:912/

in the Dockerfile, but it is not possible for me, because my proxy is only valid on my building, so if another person from another place want to build the image, he will need to remove http_proxy env var from Dockerfile.

Is there any other way to achieve it? It seems like a very common use case...

like image 806
Juliatzin Avatar asked Jan 16 '18 09:01

Juliatzin


People also ask

How do I use pip under proxy?

pip can be configured to connect through a proxy server in various ways: using the --proxy command-line option to specify a proxy in the form scheme://[user:passwd@]proxy.server:port. using proxy in a Configuration Files. by setting the standard environment-variables http_proxy , https_proxy and no_proxy .

How do I specify proxy in Dockerfile?

We simply need to set the http_proxy and https_proxy environmental variables during build time. We can do this with the docker build command itself. $ sudo docker build -t curl --build-arg http_proxy=http://192.168.33.10:3128 . Or we can specify the http_proxy value using the ENV instruction within the Dockerfile .

Should I upgrade pip in Dockerfile?

Whether you're setting up a development environment or writing your Dockerfile , make sure you upgrade pip . Otherwise you'll have a much harder time installing packages.

What is pip proxy?

A proxy server for pip is most commonly used for security and privacy, but can also be used for control: Security & Privacy – a proxy server can be used in combination with firewalls in order to improve internal network security since requests from users on the local network are anonymized via a proxy server.


2 Answers

I solved it by adding HTTPS_PROXY in command line:

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 .
like image 140
Juliatzin Avatar answered Oct 12 '22 06:10

Juliatzin


Don't include the proxy settings in the Dockerfile.

If you have configured the proxy settings correctly on the host machine, you can build the docker image with --network= host. This will make the build command use the network settings of the host.

docker build  --no-cache --network=host -t elasticsearch-curator:5.4 .
like image 38
yamenk Avatar answered Oct 12 '22 07:10

yamenk