How to build Docker Images with Dockerfile behind HTTP_PROXY by Jenkins?

后端 未结 7 1804
终归单人心
终归单人心 2020-12-23 14:54

Building Docker images works in a desktop without a problem. Installing Node.js NPM dependencies work as usual. However, when using a continuous integration server such as J

相关标签:
7条回答
  • 2020-12-23 15:03

    Note: Docker 1.9 might help solve this:

    • "Issue 14634": Builder - Build-time argument passing (e.g., HTTP_PROXY)
    • "PR 15182": Support for passing build-time variables in build context

    Usage (proposed):

    docker build --build-arg http_proxy=http://my.proxy.url  --build-arg foo=bar <<MARK
    FROM busybox
    RUN <command that need http_proxy>
    ARG --description="foo's description" foo
    USER $foo
    MARK
    
    0 讨论(0)
  • 2020-12-23 15:04

    Starting with Docker 17.07 you can alternatively use the Docker Client configuration file for providing the proxy configuration centrally:

    https://docs.docker.com/network/proxy/#configure-the-docker-client

    0 讨论(0)
  • 2020-12-23 15:05

    Docker has multiple ways to set proxies that take effect at different times.


    If your docker build has to retrieve a base image through a proxy, you'll want to specify build-args:

    docker build --build-arg HTTP_PROXY=$http_proxy \
    --build-arg HTTPS_PROXY=$http_proxy --build-arg NO_PROXY="$no_proxy" \
    --build-arg http_proxy=$http_proxy --build-arg https_proxy=$http_proxy \
    --build-arg no_proxy="$no_proxy" -t myContainer /path/to/Dockerfile/directory
    

    where $http_proxy and $no_proxy were set in my bashrc. I used both HTTP_PROXY and http_proxy because different utilities will check different variables (curl checks both, wget only checks the lowercase ones, etc).


    If your docker build has a RUN curl/wget/etc command that has to go through the proxy, you'll need to specify an environment variable inside your docker image:

    ENV https_proxy=http://proxy-us02.company.com:8080
    ENV http_proxy=http://proxy-us02.company.com:8080
    ENV HTTP_PROXY=http://proxy-us02.company.com:8080
    ENV HTTPS_PROXY=http://proxy-us02.company.com:8080
    ENV no_proxy="localhost,localdomain,127.0.0.1,etc"
    ENV NO_PROXY="localhost,localdomain,127.0.0.1,etc"
    

    If you don't want this environment variable inside your image at runtime, you can remove all these at the end:

    RUN unset http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY
    
    0 讨论(0)
  • 2020-12-23 15:05

    I had a problem when corporate network was not allowing to download and setup docker image so n/w gave http proxy information. while running docker image build I passed the variable and it worked without any issues.

      docker build  --build-arg http_proxy="http://userid:pwd@iaisystem.com:8080" - < Dockerfile
    
    0 讨论(0)
  • 2020-12-23 15:09

    We are doing ...

    ENV http_proxy http://9.9.9.9:9999
    ENV https_proxy http://9.9.9.9:9999
    

    and at end of dockerfile ...

    ENV http_proxy ""
    ENV https_proxy ""
    

    This, for now (until docker introduces build env vars), allows the proxy vars to be used for build without publicly exposing them

    0 讨论(0)
  • 2020-12-23 15:09

    You can use a transparent proxy, as described in:

    https://jpetazzo.github.io/2014/06/17/transparent-squid-proxy-docker/

    docker run --net host jpetazzo/squid-in-a-can
    iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 3129
    
    0 讨论(0)
提交回复
热议问题