Docker: npm install behind proxy
I also had the same issue and did not want to set any proxy information in my image as I did not want be dependant of my company environment.
My solution was to use a cntlm running in gateway mode. To do so I put the flag Gateway
set to yes
the following allow rules in my cntlm configuration file:
Gateway yes
# Allow local
Allow 127.0.0.1
# Allow docker subnetwork
Allow 172.17.0.0/16
Then I was able to run my docker file by getting the dokcer0 interface address (got with ifconfig
command):
docker build -t my-image --build-arg HTTP_PROXY=http://172.17.0.1:3128 --build-arg HTTPS_PROXY=http://172.17.0.1:3128 .
Same with docker run
:
docker run --rm -e HTTP_PROXY=http://172.17.0.1:3128 --build-arg HTTPS_PROXY=http://172.17.0.1:3128 my-image
However please note that since docker 17.07 you can simply configure the docker client proxy.
Hence your ~/.docker/config.json
will be like
{
"proxies": {
"default":{
"httpProxy": "http://172.17.0.1:3128/",
"httpsProxy": "http://172.17.0.1:3128/",
"noProxy": "127.0.0.1,172.17.0.0/16,*.some.compagny.domain"
}
}
First the https_proxy
should use an http url, not an https url.
Second, you don't need to embed your proxy settings in your Dockfile: you can use build time variables
docker build --build-arg HTTP_PROXY=http://user:[email protected]:3128 --build-arg HTTPS_PROXY=http://user:[email protected]:3128 .
Finally, proxy settings at the docker service level allows the docker daemon to pull images from internet. It does not mean the unix command executed (RUN
directive) by docker build
would benefit from them. Hence the need to pass them as build-time environment variables.