2

I need to connect to the Internet from inside a container.

Initially, the Docker daemon was not able to connect to the Internet and I was unable to run:

docker pull hello-world 

I resolved this by specifying a manual proxy in the docker desktop GUI settings, under resources
Once I manually set the proxy I was able to pull the hello-world image - so I know this proxy works.

I then created a test Dockerfile to see if I could get a container to connect to the internet when building an image, and this is the Dockerfile:

FROM mcr.microsoft.com/windows/servercore:1903 RUN curl 'www.google.co.za' 

and got this output:

PS C:\Projects\Test> docker build -t test:01 . Sending build context to Docker daemon 3.906GB Step 1/2 : FROM mcr.microsoft.com/windows/servercore:1903 ---> 66c07b0d3e85 Step 2/2 : RUN curl 'www.google.co.za' ---> Running in 99f79ea70731 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: 'www.google.co.za' The command 'cmd /S /C curl 'www.google.co.za'' returned a non-zero code: 6 

As was suggested here I tried adding a DNS as follows:

"dns": ["1.1.1.1"] 

but got the same result as above.
I had previously had issues in Linux containers where I couldn't install packages inside the container and I had to add the following to the Dockerfile which worked:

ENV HTTP_PROXY http://myproxy:3128 ENV http_proxy http://myproxy:3128 

I have tried doing this in my test Dockerfile and I get this result (note that this is the output without the DNS settings):

PS C:\Projects\Test> docker build -t test:01 . Sending build context to Docker daemon 3.906GB Step 1/4 : FROM mcr.microsoft.com/windows/servercore:1903 ---> 66c07b0d3e85 Step 2/4 : ENV HTTP_PROXY http://myproxy.com:3128 ---> Using cache ---> d6bbca2c1984 Step 3/4 : ENV http_proxy http://myproxy.com:3128 ---> Using cache ---> a22311c57c8d Step 4/4 : RUN curl 'www.google.co.za' ---> Running in 3e3be3786b62 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 874 100 874 0 0 874 0 0:00:01 --:--:-- 0:00:01 1189 <HTML><HEAD> <TITLE>Network Error</TITLE> </HEAD> <BODY> <FONT face="Helvetica"> <big><strong></strong></big><BR> </FONT> <blockquote> <TABLE border=0 cellPadding=1 width="80%"> <TR><TD> <FONT face="Helvetica"> <big>Network Error (dns_unresolved_hostname)</big> <BR> <BR> </FONT> </TD></TR> <TR><TD> <FONT face="Helvetica"> Your requested host "'www.google.co.za'" could not be resolved by DNS. </FONT> </TD></TR> <TR><TD> <FONT face="Helvetica"> </FONT> </TD></TR> <TR><TD> <FONT face="Helvetica" SIZE=2> <BR> For assistance, contact your network support team.<br><br>Your request was categorized by Blue Coat Web Filter as 'none'. <br>If you wish to question or dispute this result, please click <a href="http://sitereview.bluecoat.com/sitereview.jsp?referrer=136&url=http://'www.google.co.za'/">here</a>. </FONT> </TD></TR> </TABLE> </blockquote> </FONT> </BODY></HTML> Removing intermediate container 3e3be3786b62 ---> 79dcdbf32644 Successfully built 79dcdbf32644 Successfully tagged test:01 

If I add the DNS settings back into the Docker GUI I get this output:

PS C:\Projects\Test> docker build -t test:01 . Sending build context to Docker daemon 3.906GB Step 1/4 : FROM mcr.microsoft.com/windows/servercore:1903 ---> 66c07b0d3e85 Step 2/4 : ENV HTTP_PROXY http://myproxy.com:3128 ---> Running in 4ac3e6e23b5f Removing intermediate container 4ac3e6e23b5f ---> 6bfbb6923789 Step 3/4 : ENV http_proxy http://myproxy.com:3128 ---> Running in 7e7b08cef7b3 Removing intermediate container 7e7b08cef7b3 ---> 4a827371e6fa Step 4/4 : RUN curl 'www.google.co.za' ---> Running in 317a2ea37342 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:10 --:--:-- 0curl: (5) Could not resolve proxy: myproxy.com The command 'cmd /S /C curl 'www.google.co.za'' returned a non-zero code: 5 

So with the DNS settings it can't resolve the proxy and without the DNS settings it can't resolve the URL. I don't know how to proceed from here.


Removing the literal single quotes from my curl command was necessary but this hasn't solved my problem yet unfortunately.

I don't properly understand what setting the dns to "1.1.1.1" does but from the reading I did, it seemed I should rather specify the dns to the DNS server within my company's network. I discovered this info with this command:

ipconfig -all 

and there I saw 2 IP address listed as DNS servers under "Ethernet adapter Ethernet:", so I rather specified these 2 in the Docker Desktop GUI "Docker Engine" settings.

I then ran tests with 4 permutations as follows:

  1. Set DNS in Docker Desktop + set proxy ENV in Dockerfile
  2. Set DNS in Docker Desktop + no proxy set in Dockerfile
  3. No DNS set in Docker Desktop + set proxy ENV in Dockerfile
  4. No DNS set in Docker Desktop + no proxy set in Dockerfile

In each test I tried to run the following commands from my dockerfile during the build:

RUN curl www.google.co.za RUN tracert www.google.co.za 

Setting the DNS didn't seem to make any difference to the results. Setting the ENV HTTP_PROXY set in the Dockerfile seemed to make a difference to the curl command. Without setting it I get the following output:

Failed to connect to www.google.co.za port 80: Timed out 

With the ENV HTTP_PROXY set in the Dockerfile I get what looks like the HTML of the google.co.za site which makes it appear to be working. But the tracert command shows that the request gets out of the container but doesn't get past my default gateway and it reports "Destination host unreachable". So instead of running the curl command to www.google.co.za I used a banks site and here the curl command reports:

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:10 --:--:-- 0 

and the tracert command fails. I am guessing that when running curl www.google.co.za, I am getting a cached page somehow.

So I am still stuck and looking for help.

5
  • You can't traceroute when you have to access the web via a proxy. So you don't need to worry about that or even make any attempts to do so. Commented Jul 10, 2020 at 12:15
  • I am not very knowledgeable about the finer details of networking but I was under the impression that tracert could be used to see how far the request went which is why I was trying this. It looks like the request gets out of the container but not past my host's default gateway. Am I misunderstanding this result? Commented Jul 10, 2020 at 12:20
  • Even if tracert is not useful here, I am still stuck and unable to connect to the internet from within my container. Commented Jul 10, 2020 at 12:22
  • You should contact your proxy server administrator. It is possible that they have blocked access to various web sites. Commented Jul 10, 2020 at 12:28
  • I can access these websites from the host PC, but not when building the docker image. So I don't think that is the problem, but I'm not sure. Commented Jul 10, 2020 at 12:31

1 Answer 1

0

You should remove the literal single quotes from your curl command. They are being sent to the proxy server, so that it tries to find a host named 'www.google.co.za' instead of the desirable www.google.co.za.

It should instead be:

RUN curl www.google.co.za 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.