How to create Docker Images with Dockerfile for HTTP_PROXY from Jenkins?

Building Docker images work on the desktop without problems. Dependency Installation NPM Node.js works as usual. However, when using a continuous integration server, such as Jenkins, which is located behind the corporate proxy server, the Docker Images assembly fails.

Node.js NPM Dependencies

When building Node.js pacakges, the npm install command fails if it cannot connect to GIT when cloning GIT dependencies.

e1ce5e8407d1: Already exists Status: Image is up to date for node:0.10.33 ---> e1ce5e8407d1 Step 1 : RUN mkdir -p /usr/src/app ---> Using cache ---> 965cad0c68b0 Step 2 : WORKDIR /usr/src/app ---> Using cache ---> 4c498f0c07e9 Step 3 : COPY package.json /usr/src/app/ ---> b0662a8275fb Removing intermediate container 5aca20551452 Step 4 : RUN npm install ---> Running in 7ccf9e5362af npm WARN package.json newww@2.0.0 No README data npm WARN package.json Dependency 'async-cache' exists in both dependencies and devDependencies, using 'async-cache@^0.1.5' from dependencies npm ERR! git clone https://github.com/npm/npm2es.git Cloning into bare repository '/root/.npm/_git-remotes/https-github-com-npm-npm2es-git-60a75edb'... npm ERR! git clone https://github.com/npm/npm2es.git fatal: unable to access 'https://github.com/npm/npm2es.git/': Failed to connect to github.com port 443: Connection timed out 

Java Maven, Ruby, Go Docker Dependency Images

The same thing happens when creating Java, Ruby or Go containers, where the dependencies are located on the repository servers on your corporate proxy server.

Knowing that you can configure Docker with the HTTP_PROXY environment variable, how to properly configure Docker to properly assemble images in CI environments?

+20
git maven docker npm dockerfile
Jan 02 '15 at 22:08
source share
7 answers

Note. Docker 1.9 can help solve this problem:

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

Use (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 description" foo USER $foo MARK 
+36
Aug 13 '15 at 11:58
source

Docker Daemon HTTP Proxy

There is a lot of documentation about setting the HTTP_PROXY environment variable for the Docker daemon. The environment variable is available only in working containers , so this will not help us.

Solution in Dockerfile

Although setting the environment variable HTTP_ENV or http_env in the Docker file may help, this also does not help our cause.

ENV http_proxy http://proxy.mycompany.com:80

The reason is that each particular service only differs the HTTP proxy setting in a different way. How I can decide is below.

  • NPM: NPM requires the configuration of the HTTP_PROXY variable using the CLI command.
  • GIT: GIT requires the HTTP_PROXY variable to be configured using the CLI command.
  • MAVEN: the MVN command requires setting HTTP_PROXY as the XML file in the user directory in ~ .m2 / settings.xml . For Docker, you can add it to the root directory "/root/.m2/settings.xml" (unsafe, only for development) or to the home directory of the Dockerfile user.

For example, running the application using the Dockerfile, I can create the image using the following Docker file:

 FROM node:0.10.33 # Prepare RUN mkdir -p /usr/src/app WORKDIR /usr/src/app # Use the cache for dependencies COPY package.json /usr/src/app/ # If building behind an http_proxy, set them for git and npm RUN git config --global http.proxy http://qypprdproxy02.ie.company.net:80 && \ npm config set proxy http://qypprdproxy02.ie.company.net:80 && \ npm config set https-proxy http://qypprdproxy02.ie.company.net:80 # Install dependencies RUN npm install # Copy all the source COPY . /usr/src/app # Execute the dev steps COPY ./numbat-config.example.js /usr/src/app/numbat-config.js COPY ./.env.example /usr/src/app/.evn RUN touch /usr/src/app/config.admin.js 

Note that I configured both GIT and NPM using the CLI command to explicitly configure the proxy server before running the NPM install command. Thus, the dependencies between NPM and GIT will be automatically restored and cloned accordingly.

The result of creating an image with this Docker file works as expected:

 [root@pppdc9prd6dq newww]# fig build ... ... Building npmregistryserver... ---> Using cache ---> 965cad0c68b0 Step 2 : WORKDIR /usr/src/app ---> Using cache ---> 4c498f0c07e9 Step 3 : COPY package.json /usr/src/app/ ---> ae8ff7861246 Removing intermediate container ba1d7b8c9963 Step 4 : RUN npm config set proxy http://qypprdproxy02.ie.company.net:80 && npm config set https-proxy http://qypprdproxy02.ie.company.net:80 && npm install ---> Running in aa6e05d9c7a4 npm WARN package.json newww@2.0.0 No README data npm WARN package.json Dependency 'async-cache' exists in both dependencies and devDependencies, using 'async-cache@^0.1.5' from dependencies npm WARN deprecated extend@1.1.3: Please update to the latest version. > v8flags@1.0.8 install /usr/src/app/node_modules/gulp/node_modules/v8flags > node fetch.js > hiredis@0.1.17 install /usr/src/app/node_modules/hiredis > node-gyp rebuild make: Entering directory '/usr/src/app/node_modules/hiredis/build' CC(target) Release/obj.target/hiredis/deps/hiredis/hiredis.o CC(target) Release/obj.target/hiredis/deps/hiredis/net.o CC(target) Release/obj.target/hiredis/deps/hiredis/sds.o CC(target) Release/obj.target/hiredis/deps/hiredis/async.o AR(target) Release/obj.target/deps/hiredis.a COPY Release/hiredis.a CXX(target) Release/obj.target/hiredis/src/hiredis.o CXX(target) Release/obj.target/hiredis/src/reader.o SOLINK_MODULE(target) Release/obj.target/hiredis.node SOLINK_MODULE(target) Release/obj.target/hiredis.node: Finished COPY Release/hiredis.node make: Leaving directory '/usr/src/app/node_modules/hiredis/build' npm WARN engine hawk@0.10.2: wanted: {"node":"0.8.x"} (current: {"node":"0.10.33","npm":"2.1.11"}) > pngcrush-bin@1.0.0 postinstall /usr/src/app/node_modules/imagemin-pngcrush/node_modules/pngcrush-bin > node lib/install.js fetch : https://raw.githubusercontent.com/imagemin/pngcrush-bin/v1.0.0/vendor/linux/pngcrush โœ” pre-build test passed successfully! > dtrace-provider@0.3.1 install /usr/src/app/node_modules/npm-typeahead/node_modules/restify/node_modules/dtrace-provider > scripts/install.js npm WARN engine cryptiles@0.1.3: wanted: {"node":"0.8.x"} (current: {"node":"0.10.33","npm":"2.1.11"}) npm WARN engine sntp@0.1.4: wanted: {"node":"0.8.x"} (current: {"node":"0.10.33","npm":"2.1.11"}) npm WARN engine boom@0.3.8: wanted: {"node":"0.8.x"} (current: {"node":"0.10.33","npm":"2.1.11"}) npm WARN engine hoek@0.7.6: wanted: {"node":"0.8.x"} (current: {"node":"0.10.33","npm":"2.1.11"}) npm WARN cannot run in wd newww@2.0.0 gulp build (wd=/usr/src/app) newww-metrics@1.0.0 node_modules/newww-metrics murmurhash@0.0.2 node_modules/murmurhash npm-humans@2.0.1 node_modules/npm-humans leven@1.0.1 node_modules/leven chunk@0.0.2 node_modules/chunk npm-expansions@1.14.0 node_modules/npm-expansions similarity@1.0.1 node_modules/similarity truncate@1.0.4 node_modules/truncate 

This worked correctly as expected, and you can have a CI / CD environment behind an HTTP proxy to restore images based on this Docker file.

+11
Jan 02 '15 at 22:25
source

I had to do

 docker build --no-cache --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 installed in my bashrc. I used HTTP_PROXY and http_proxy , because different utilities will check different variables ( curl checks both, wget checks only lowercase, etc.). Setting ENV http_proxy http://proxy.mycompany.com:80 did not help, as I tried to use these variables at build time, and not at run time.

+11
Oct 20 '17 at 19:40
source

We do...

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

and at the end of the docker file ...

 ENV http_proxy "" ENV https_proxy "" 

This, until (until the docker introduces build env vars), allows the use of proxies for assembly without publicly displaying them

+3
Jul 16 '15 at 16:40
source

Starting with Docker 17.07, you can also use the Docker Client configuration file to centrally provide the proxy configuration:

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

+2
Aug 08 '18 at 6:11
source

I had a problem when the corporate network did not allow loading and configuring the docker image, so n / w provided http proxy information. when I started assembling the docker image, I passed a variable, and it worked without problems.

  docker build --build-arg http_proxy="http://userid:pwd@iaisystem.com:8080" - < Dockerfile 
0
May 18 '18 at 16:00
source

You can use a transparent proxy as described in:

https://jpetazzo.imtqy.com/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
Jul 26 '18 at 19:03
source



All Articles