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

后端 未结 7 1842
终归单人心
终归单人心 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: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
    

提交回复
热议问题