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://]<host>[:port]
Sets the proxy server to use for HTTP.
HTTPS_PROXY [protocol://]<host>[:port]
Sets the proxy server to use for HTTPS.
FTP_PROXY [protocol://]<host>[:port]
Sets the proxy server to use for FTP.
ALL_PROXY [protocol://]<host>[:port]
Sets the proxy server to use if no protocol-specific proxy is set.
NO_PROXY <comma-separated list of hosts>
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.
-p 7000:8000
in your first command - is it a typo or a cause of your problem?