<p>I believe that the problem lies on your proxy environment variables.</p>

<pre><code>$ docker run \
    --name myjenkins \
    -p 7000:8080 \
    -p 50000:50000 \
    --env HTTP_PROXY="http:// localhost:8080" \
    --env HTTPS_PROXY="https:// localhost:8080" \
    -v /var/jenkins_home \
    jenkins
</code></pre>

<p>The values of <code>$HTTP_PROXY</code> and <code>$HTTP_PROXY</code> are not supposed to have space characters on them and the protocol should be <code>http</code>. Additionally, although setting <code>$HTTP_PROXY</code> is useful for compatibility with other applications running inside the container, <code>curl</code> expects the HTTP proxy environment variable to be written in lowercase, that is, <code>$http_proxy</code>. From <a href="https://linux.die.net/man/1/curl" rel="nofollow noreferrer"><code>curl (1)</code> manual page</a>:</p>

<blockquote>
  <h2>Environment</h2>
  
  <p>The environment variables can be specified in lower case or upper case. The lower case version has precedence. <code>http_proxy</code> is an exception as it is only available in lower case.</p>
  
  <p><code>http_proxy [protocol://]&lt;host&gt;[:port]</code>
  Sets the proxy server to use for HTTP.</p>
  
  <p><code>HTTPS_PROXY [protocol://]&lt;host&gt;[:port]</code>
  Sets the proxy server to use for HTTPS.</p>
  
  <p><code>FTP_PROXY [protocol://]&lt;host&gt;[:port]</code>
  Sets the proxy server to use for FTP.</p>
  
  <p><code>ALL_PROXY [protocol://]&lt;host&gt;[:port]</code>
  Sets the proxy server to use if no protocol-specific proxy is set.</p>
  
  <p><code>NO_PROXY &lt;comma-separated list of hosts&gt;</code>
  list of host names that shouldn't go through any proxy. If set to a asterisk '*' only, it matches all hosts.</p>
</blockquote>

<p>Therefore the <code>docker run</code> command might be written as below:</p>

<pre><code>$ docker run \
    --name myjenkins \
    -p 7000:8080 \
    -p 50000:50000 \
    --env HTTP_PROXY="http://localhost:8080" \
    --env http_proxy="http://localhost:8080" \
    --env HTTPS_PROXY="http://localhost:8080" \
    --env https_proxy="http://localhost:8080" \
    -v /var/jenkins_home \
    jenkins
</code></pre>

<p>However, my solution will certainly not work because the port 8080 inside the container is being used by Jenkins and not by a HTTP proxy. Please, could you provide more information on how your work proxy is set up so I can edit my answer with more accurate details? Are you running a HTTP proxy such as <code>squid</code> or <code>cntlm</code> in your computer that receives requests from applications running in your workstation and forwards them to the corporate proxy after authentication? If so, you will need to adjust container's network configuration according to Stack Overflow question <a href="https://stackoverflow.com/q/24319662">From inside of a Docker container, how do I connect to the localhost of the machine?</a>.</p>

<hr>

<p><strong>EDIT:</strong> According to comments, a <code>cntlm</code> instance running locally on port <code>8080/tcp</code> provides a HTTP proxy service that local applications must use in order to access internet. I believe that the least complex way to expose it to Jenkins container is by specifying <code>--network=host</code> parameter and sharing <a href="https://lwn.net/Articles/580893/" rel="nofollow noreferrer">the root network namespace</a> with the Jenkins container. However, Jenkins is set to listen the port <code>8080/tcp</code> by default, therefore it must be instructed to listen to an alternative port, such as <code>7000/tcp</code>. That can be achieved by passing <a href="https://stackoverflow.com/a/15265306"><code>--httpPort=#</code> command line argument</a> to Jenkins via <a href="https://github.com/jenkinsci/docker/blob/master/README.md#passing-jenkins-launcher-parameters" rel="nofollow noreferrer"><code>JENKINS_OPTS</code> environment variable</a>.</p>

<p><strong>EDIT 2:</strong> While analyzing the <a href="https://github.com/jenkinsci/docker/" rel="nofollow noreferrer">repository code</a>, I've realized that Jenkins is a Java application and I am not sure that JVM recognizes <code>$http_proxy</code> and <code>$https_proxy</code> environment variables properly. So, to ensure that Jenkins will use <code>cntlm</code> as HTTP proxy, I also suggest passing <a href="https://docs.oracle.com/javase/8/docs/api/java/net/doc-files/net-properties.html" rel="nofollow noreferrer">proxy configuration properties</a> to the JVM via the <a href="https://github.com/jenkinsci/docker/blob/master/README.md#passing-jvm-parameters" rel="nofollow noreferrer"><code>JAVA_OPTS</code> environment variable</a>.</p>

<p><strong>EDIT 3:</strong> The Docker image <a href="https://hub.docker.com/_/jenkins" rel="nofollow noreferrer"><code>jenkins</code></a> is deprecated in favor of the <a href="https://hub.docker.com/r/jenkins/jenkins" rel="nofollow noreferrer"><code>jenkins/jenkins:lts</code></a> one. The former image is currently unmaintained and seems to contain a version that is outdated and incompatible with plugins being downloaded.</p>

<p>To sum up, the <code>docker run</code> command have to be written as below for Jenkins to work in your environment:</p>

<pre><code>$ docker run \
    --name myjenkins \
    --network=host \
    --env HTTP_PROXY="http://localhost:8080" \
    --env http_proxy="http://localhost:8080" \
    --env HTTPS_PROXY="http://localhost:8080" \
    --env https_proxy="http://localhost:8080" \
    --env JAVA_OPTS="-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8080 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=8080" \
    --env JENKINS_OPTS="--httpPort=7000" \
    -v /var/jenkins_home \
    jenkins/jenkins:lts
</code></pre>

<p>Passing <code>--env JAVA_OPTS="-Djava.net.useSystemProxies=true"</code> instead might work. I am not able to perform a try, though.</p>

CC BY-SA 4.0
2020-05-20T11:45:48.113Z
Thank you for your help. The spacing it's just some formatting error during the copy and paste. I've tried to run the container with lowercase environment variables but still not any luck. I get the same plugin error as above as well as not being able to configure the proxy within the Jenkins UI.

I connect through Netscaler, it's a cntlm VPN I believe. I connect using a password and authentication code.

I've tried the solution on the link you've provided, using --network="host", but it didn't work
Sgr
CC BY-SA 4.0
2020-05-20T13:58:48.797Z
@Sgr Could you recheck my answer? I believe that the edited one will work for you.
Anderson Medeiros Gomes
CC BY-SA 4.0
2020-05-21T19:14:36.453Z
Thank you, that worked like a charm. It's a bit of a kill having so many proxy settings but if I understand you correctly, this is what you've done:
set network=="host" so that the container can use docker host cntlm to get to internet. 2)set http/https proxy in the docker environment so that curl can connect to hos.
3) set proxy settings for java/jenkins so that jenkins can connect the internet as well as use port=7000. I'll now try to put all these settings in a Dockerfile
Sgr
CC BY-SA 4.0
2020-05-21T20:46:04.293Z
Thanks for you feedback. You've understood correctly. Another change that I made and is actually not related to proxy environment is the reference to the image `jenkins/jenkins:lts` instead of `jenkins`. Because the latter has been deprecated, it uses a version that is outdated and incompatible with plugins being downloaded.
Anderson Medeiros Gomes
CC BY-SA 4.0
2020-05-21T20:51:42.390Z
Did `--env JAVA_OPTS="-Djava.net.useSystemProxies=true"` work for you?
Anderson Medeiros Gomes
CC BY-SA 4.0
2020-05-21T22:46:23.270Z
I did not try that option.  I will try it tomorrow and let you know. Thanks
Sgr
CC BY-SA 4.0
2020-05-19T07:08:25.803Z
2020-05-21T20:50:16.443Z
2020-05-21T20:50:16.443Z
Anderson Medeiros Gomes
<p>For the past few days I’ve been scratching my head trying to get the Jenkins docker image to work</p>

<p>The issue appears to be a proxy issue.</p>

<blockquote>
  <p>OS: Ubuntu 16.04 LTS  </p>
  
  <p>Running behind work proxy </p>
  
  <p>Docker version 19.03.5, build 633a0ea838 </p>
  
  <p>Jenkins:<a href="https://hub.docker.com/_/jenkins/" rel="nofollow noreferrer">https://hub.docker.com/_/jenkins/</a></p>
</blockquote>

<p>When I run the following command, I can’t access jenkins on localhost:7000</p>

<pre><code>docker run --name myjenkins -p 7000:8080 -p 50000:50000 -v /var/jenkins_home jenkins
</code></pre>

<p>However I can with the following command</p>

<pre><code>docker run --name myjenkins -p 7000:8080 -p 50000:50000 --env HTTP_PROXY="http:// localhost:8080" --env HTTPS_PROXY="https:// localhost:8080" -v /var/jenkins_home jenkins
</code></pre>

<p>The issue is, with the second command, I can access the Jenkins but I can’t install plugins and it asks me to configure the proxy
Setting the proxy in the UI didn’t work</p>

<p>My understanding is that Jenkins look for port 8080 by default and because in the command above I’m using port 7000, this is preventing Jenkins from connecting to the internet (correct me if I’m wrong)</p>

<p>So what I did was download the Dockerfile for Jenkins and changed the port from 8080 to 7000</p>

<p><strong><a href="https://github.com/jenkinsci/docker/blob/587b2856cd225bb152c4abeeaaa24934c75aa460/Dockerfile" rel="nofollow noreferrer">Dockerfile</a></strong></p>

<p>I am now attempting to build the image with the following command</p>

<pre><code>docker build --tag jenkins:1.0 .
</code></pre>

<p>I get the following error</p>

<pre><code>curl: (7) Failed to connect to github. com port 443: Connection timed out
The command '/bin/sh -c curl -fsSL https:// github. com/krallin/tini/releases/download/v${TINI_VERSION}/tini-static-amd64 -o /bin/tini &amp;&amp; chmod +x /bin/tini &amp;&amp; echo "$TINI_SHA /bin/tini" | sha256sum -c -' returned a non-zero code: 7
</code></pre>

<p>I suspect, this is a proxy issue and I did put proxy arguments in the Dockerfile but not sure if this is what I need to do or whether I’m doing it correctly</p>

<p>Any idea what could be the solution?</p>

<p>Thank you</p>

CC BY-SA 4.0
2020-05-16T00:02:13.793Z
You have `-p 7000:8000` in your first command - is it a typo or a cause of your problem?
taleodor
CC BY-SA 4.0
2020-05-16T11:13:28.097Z
It's not a typo, I want 7000 as 8080 is already in use, hence me changing the Dockerfile default port from 8080 to 7000
Sgr
CC BY-SA 4.0
2020-05-16T11:53:18.170Z
I meant 8000 instead of 8080.
taleodor
CC BY-SA 4.0
2020-05-16T12:25:58.743Z
yes, sorry, it's a typo
Sgr
<docker><jenkins><jenkins-plugins>
how to run Docker/Jenkins behind a proxy
Sgr
# how to run Docker/Jenkins behind a proxy

(Asked by: username_0 on 2020-05-15)

For the past few days I’ve been scratching my head trying to get the Jenkins docker image to work
The issue appears to be a proxy issue.

OS: Ubuntu 16.04 LTS  
Running behind work proxy 
Docker version 19.03.5, build 633a0ea838 
Jenkins:https://hub.docker.com/_/jenkins/

When I run the following command, I can’t access jenkins on localhost:7000
docker run --name myjenkins -p 7000:8080 -p 50000:50000 -v /var/jenkins_home jenkins

However I can with the following command
docker run --name myjenkins -p 7000:8080 -p 50000:50000 --env HTTP_PROXY="http:// localhost:8080" --env HTTPS_PROXY="https:// localhost:8080" -v /var/jenkins_home jenkins

The issue is, with the second command, I can access the Jenkins but I can’t install plugins and it asks me to configure the proxy
Setting the proxy in the UI didn’t work
My understanding is that Jenkins look for port 8080 by default and because in the command above I’m using port 7000, this is preventing Jenkins from connecting to the internet (correct me if I’m wrong)
So what I did was download the Dockerfile for Jenkins and changed the port from 8080 to 7000
Dockerfile
I am now attempting to build the image with the following command
docker build --tag jenkins:1.0 .

I get the following error
curl: (7) Failed to connect to github. com port 443: Connection timed out
The command '/bin/sh -c curl -fsSL https:// github. com/krallin/tini/releases/download/v${TINI_VERSION}/tini-static-amd64 -o /bin/tini && chmod +x /bin/tini && echo "$TINI_SHA /bin/tini" | sha256sum -c -' returned a non-zero code: 7

I suspect, this is a proxy issue and I did put proxy arguments in the Dockerfile but not sure if this is what I need to do or whether I’m doing it correctly
Any idea what could be the solution?
Thank you

**Tags:** docker, jenkins, jenkins-plugins

> **Comments:**
> **username_1**: You have `-p 7000:8000` in your first command - is it a typo or a cause of your problem?  
> **username_0**: It's not a typo, I want 7000 as 8080 is already in use, hence me changing the Dockerfile default port from 8080 to 7000  
> **username_1**: I meant 8000 instead of 8080.  
> **username_0**: yes, sorry, it's a typo  

---

## 1 answers

### Answer by username_2 on 2020-05-19. Score: 3 | Accepted answer

I believe that the problem lies on your proxy environment variables.
$ docker run \
    --name myjenkins \
    -p 7000:8080 \
    -p 50000:50000 \
    --env HTTP_PROXY="http:// localhost:8080" \
    --env HTTPS_PROXY="https:// localhost:8080" \
    -v /var/jenkins_home \
    jenkins

The values of $HTTP_PROXY and $HTTP_PROXY are not supposed to have space characters on them and the protocol should be http. Additionally, although setting $HTTP_PROXY is useful for compatibility with other applications running inside the container, curl expects the HTTP proxy environment variable to be written in lowercase, that is, $http_proxy. From curl (1) manual page:

Environment
The environment variables can be specified in lower case or upper case. The lower case version has precedence. http_proxy is an exception as it is only available in lower case.
http_proxy [protocol://][:port]
  Sets the proxy server to use for HTTP.
HTTPS_PROXY [protocol://][:port]
  Sets the proxy server to use for HTTPS.
FTP_PROXY [protocol://][:port]
  Sets the proxy server to use for FTP.
ALL_PROXY [protocol://][:port]
  Sets the proxy server to use if no protocol-specific proxy is set.
NO_PROXY 
  list of host names that shouldn't go through any proxy. If set to a asterisk '*' only, it matches all hosts.

Therefore the docker run command might be written as below:
$ docker run \
    --name myjenkins \
    -p 7000:8080 \
    -p 50000:50000 \
    --env HTTP_PROXY="http://localhost:8080" \
    --env http_proxy="http://localhost:8080" \
    --env HTTPS_PROXY="http://localhost:8080" \
    --env https_proxy="http://localhost:8080" \
    -v /var/jenkins_home \
    jenkins

However, my solution will certainly not work because the port 8080 inside the container is being used by Jenkins and not by a HTTP proxy. Please, could you provide more information on how your work proxy is set up so I can edit my answer with more accurate details? Are you running a HTTP proxy such as squid or cntlm in your computer that receives requests from applications running in your workstation and forwards them to the corporate proxy after authentication? If so, you will need to adjust container's network configuration according to Stack Overflow question From inside of a Docker container, how do I connect to the localhost of the machine?.

EDIT: According to comments, a cntlm instance running locally on port 8080/tcp provides a HTTP proxy service that local applications must use in order to access internet. I believe that the least complex way to expose it to Jenkins container is by specifying --network=host parameter and sharing the root network namespace with the Jenkins container. However, Jenkins is set to listen the port 8080/tcp by default, therefore it must be instructed to listen to an alternative port, such as 7000/tcp. That can be achieved by passing --httpPort=# command line argument to Jenkins via JENKINS_OPTS environment variable.
EDIT 2: While analyzing the repository code, I've realized that Jenkins is a Java application and I am not sure that JVM recognizes $http_proxy and $https_proxy environment variables properly. So, to ensure that Jenkins will use cntlm as HTTP proxy, I also suggest passing proxy configuration properties to the JVM via the JAVA_OPTS environment variable.
EDIT 3: The Docker image jenkins is deprecated in favor of the jenkins/jenkins:lts one. The former image is currently unmaintained and seems to contain a version that is outdated and incompatible with plugins being downloaded.
To sum up, the docker run command have to be written as below for Jenkins to work in your environment:
$ docker run \
    --name myjenkins \
    --network=host \
    --env HTTP_PROXY="http://localhost:8080" \
    --env http_proxy="http://localhost:8080" \
    --env HTTPS_PROXY="http://localhost:8080" \
    --env https_proxy="http://localhost:8080" \
    --env JAVA_OPTS="-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8080 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=8080" \
    --env JENKINS_OPTS="--httpPort=7000" \
    -v /var/jenkins_home \
    jenkins/jenkins:lts

Passing --env JAVA_OPTS="-Djava.net.useSystemProxies=true" instead might work. I am not able to perform a try, though.

> **Comments:**
> **username_0**: Thank you for your help. The spacing it's just some formatting error during the copy and paste. I've tried to run the container with lowercase environment variables but still not any luck. I get the same plugin error as above as well as not being able to configure the proxy within the Jenkins UI.  I connect through Netscaler, it's a cntlm VPN I believe. I connect using a password and authentication code.  I've tried the solution on the link you've provided, using --network="host", but it didn't work  
> **username_2**: @username_0 Could you recheck my answer? I believe that the edited one will work for you.  
> **username_0**: Thank you, that worked like a charm. It's a bit of a kill having so many proxy settings but if I understand you correctly, this is what you've done: set network=="host" so that the container can use docker host cntlm to get to internet. 2)set http/https proxy in the docker environment so that curl can connect to hos. 3) set proxy settings for java/jenkins so that jenkins can connect the internet as well as use port=7000. I'll now try to put all these settings in a Dockerfile  
> **username_2**: Thanks for you feedback. You've understood correctly. Another change that I made and is actually not related to proxy environment is the reference to the image `jenkins/jenkins:lts` instead of `jenkins`. Because the latter has been deprecated, it uses a version that is outdated and incompatible with plugins being downloaded.  
> **username_2**: Did `--env JAVA_OPTS="-Djava.net.useSystemProxies=true"` work for you?  
> **username_0**: I did not try that option.  I will try it tomorrow and let you know. Thanks  

---

