如何使用docker从代理后面运行pip3 + git?

时间:2017-01-05 16:30:42

标签: python git docker proxy

如何在使用pip3运行时设置git代理?

按照https://github.com/nouiz/Theano-Docker

的说明操作

当我运行docker build -t theano_simple -f Dockerfile.0.8.X.jupyter.cuda.simple .时,我收到错误:

fatal: unable to connect to github.com:
github.com[0: 192.30.253.112]: errno=Connection timed out
github.com[1: 192.30.253.113]: errno=Connection timed out

将代理参数添加到docker文件:

RUN git config --global http.proxy myproxy:1111
RUN git config --global https.proxy myproxy:1111

ENV HTTPS_PROXY = https://myproxy:1111 ENV HTTPS_PROXY = https://myproxy:1111 ENV https_proxy = https://myproxy:1111 ENV https_proxy = https://myproxy:1111

以下是原始泊坞文件:https://github.com/nouiz/Theano-Docker/blob/master/Dockerfile.0.8.X.jupyter.cuda.simple

    FROM nvidia/cuda:7.5-cudnn5-devel

    MAINTAINER FIX ME <fixme@example.com>

    RUN apt-get update && apt-get install -y --no-install-recommends \
            git \
            libopenblas-dev \
            libzmq3-dev \
            python3-dev \
            python3-numpy \
            python3-pip \
            python3-scipy && \
        rm -rf /var/lib/apt/lists/*

    RUN pip3 install \
            ipykernel \
            jupyter && \
        python3 -m ipykernel.kernelspec

    RUN pip3 install nose nose-parameterized

    ENV THEANO_VERSION 0.8.2

    RUN pip3 install git+git://github.com/theano/theano.git@rel-${THEANO_VERSION}

    COPY theanorc /root/.theanorc

    COPY start-notebook.sh /usr/local/bin/

    COPY jupyter_notebook_config_simple.py /root/.jupyter/jupyter_notebook_config.py

    COPY notebook /opt/notebook

    RUN apt-get update && apt-get install -y curl
    RUN mkdir /opt/data && cd /opt/data && curl http://www.iro.umontreal.ca/~lisa/deep/data/mnist/mnist_py3k.pkl.gz -o mnist.pkl.gz

使用代理命令修改的docker文件:

     FROM nvidia/cuda:7.5-cudnn5-devel

        MAINTAINER FIX ME <fixme@example.com>

        RUN apt-get update && apt-get install -y --no-install-recommends \
                git \
                libopenblas-dev \
                libzmq3-dev \
                python3-dev \
                python3-numpy \
                python3-pip \
                python3-scipy && \
            rm -rf /var/lib/apt/lists/*

        RUN pip3 install \
                ipykernel \
                jupyter && \
            python3 -m ipykernel.kernelspec

        RUN pip3 install nose nose-parameterized

        ENV THEANO_VERSION 0.8.2

ENV HTTPS_PROXY=https://myproxy:1111
ENV HTTPS_PROXY=https://myproxy:1111
ENV https_proxy=https://myproxy:1111
ENV https_proxy=https://myproxy:1111

        RUN pip3 install git+git://github.com/theano/theano.git@rel-${THEANO_VERSION}

    RUN git config --global http.proxy myproxy:1111
    RUN git config --global https.proxy myproxy:1111

        COPY theanorc /root/.theanorc

        COPY start-notebook.sh /usr/local/bin/

        COPY jupyter_notebook_config_simple.py /root/.jupyter/jupyter_notebook_config.py

        COPY notebook /opt/notebook

        RUN apt-get update && apt-get install -y curl
        RUN mkdir /opt/data && cd /opt/data && curl http://www.iro.umontreal.ca/~lisa/deep/data/mnist/mnist_py3k.pkl.gz -o mnist.pkl.gz

我还尝试将代理作为pip3 installpip3 install --proxy myproxy:1111命令的一部分传递但是同样的错误。

3 个答案:

答案 0 :(得分:1)

fatal: unable to connect to github.com:
github.com[0: 192.30.253.112]: errno=Connection timed out
github.com[1: 192.30.253.113]: errno=Connection timed out

错误消息似乎是由RUN pip3 install引起的,因此为git添加代理不起作用。

您可以尝试在HTTPS_PROXY之前添加pip install env。

ENV HTTPS_PROXY=https://myproxy:1111

Using pip behind a proxy

答案 1 :(得分:0)

您是否尝试过以下操作?

pip3 install yourmodulename --trusted-host pypi.python.org

答案 2 :(得分:0)

问题可能是您在公司代理/防火墙的后面,并且传出连接在某处被阻止。一个简单的解决方案是将命令更改为https版本:

更改:

pip3 install git+git://github.com/theano/theano.git@rel-${THEANO_VERSION}

收件人:

pip3 install git+https://github.com/theano/theano.git@rel-${THEANO_VERSION}

或者:

您可能要尝试以下步骤:https://help.github.com/articles/using-ssh-over-the-https-port/

这将通过大多数公司允许的https协议重定向所有git连接:)

祝你好运!