I have this Dockerfile:
FROM node:argon
ENV http_proxy http://user:[email protected]:3128
ENV https_proxy https://user:[email protected]:3128
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 8080
CMD [ "npm", "start" ]
But I get this error, in npm install step:
npm info it worked if it ends with ok npm info using [email protected] npm info using [email protected] npm WARN package.json [email protected] No description npm WARN package.json [email protected] No repository field. npm WARN package.json [email protected] No README data npm info preinstall [email protected] npm info attempt registry request try #1 at 7:09:23 AM npm http request GET https://registry.npmjs.org/body-parser npm info attempt registry request try #1 at 7:09:23 AM npm http request GET https://registry.npmjs.org/express npm info retry will retry, error on last attempt: Error: tunneling socket could not be established, cause=write EPROTO npm info retry will retry, error on last attempt: Error: tunneling socket could not be established, cause=write EPROTO
I guess it is due to the proxy. I have also tried to put
RUN npm config set proxy http://user:[email protected]:3128
RUN npm config set https-proxy http://user:[email protected]:3128
but still getting the same error.
Moreover, in my file /etc/systemd/system/docker.service.d/http-proxy.conf I have this:
Environment="HTTP_PROXY=http://user:[email protected]:3128"
Environment="HTTPS_PROXY=https://user:[email protected]:3128"
Thanks in advance.
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.
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"
}
}
Adding this to Dockerfile worked for me:
RUN npm config set https-proxy http://user:[email protected]:80
RUN npm config set proxy http://user:[email protected]:80
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"
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With