I have this Dockerfile:
FROM node:argon
ENV http_proxy http://user:pass@proxy.company.priv:3128
ENV https_proxy https://user:pass@proxy.company.priv:3128
RUN m
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:pass@proxy.company.priv:3128 --build-arg HTTPS_PROXY=http://user:pass@proxy.company.priv: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.
As described in the Docker Documentation adding the following to ~/.docker/config.json
helped me:
{
"proxies":
{
"default":
{
"httpProxy": "http://127.0.0.1:3001",
"httpsProxy": "http://127.0.0.1:3001",
"noProxy": "*.test.example.com,.example2.com"
}
}
}
(Just that you know, this package was written by myself)
You can use docker-container-proxy, it allows configuration of a proxy for any docker container without editing any code.
Just run:
npx dockerproxy start --address company-proxy-address.com --port 8080
# Do anything else that needs a Proxy
Adding this to Dockerfile worked for me:
RUN npm config set https-proxy http://user:password@proxy.company.priv:80
RUN npm config set proxy http://user:password@proxy.company.priv:80