Build issue: apt-get cannot connect to archive.ubuntu.com

I’m working through the “Getting Started with Docker” tutorial. I’m working within a corporate network. I followed the troubleshooting hints and edited /var/lib/boot2docker/profile in my default docker machine to configure it for the corporate network proxy. That worked and allowed general access beyond the corporate network.
However, when I reached the “Build your own image” step in the tutorial I the apt-get of archive.ubuntu.com is failing during the build saying that it cannot connect. I see that this is an IPv6 address and perhaps that is the issue. I’ve read through the docs I can find on IPv6, but have not been able to figure this out. This seems like it may be a general issue, but I could not find a solution in the forums. If I’ve missed it, please point me in the right direction.

Expected behavior

The build should succeed and apt-get should be able to connect with archive.ubuntu.com.

Actual behavior

The build fails because apt-get cannot connect to archive.ubuntu.com

Information

I’m running this on my laptop running Windows 7.
Docker version: 1.11.2
I verified that I can connect to http://archive.ubuntu.com via FireFox from my laptop.
My guess is that this is related to the fact that this is an IPv6 address and for some reason this is not working.

Steps to reproduce the behavior

See https://docs.docker.com/windows/step_four/ for the context.
Here is the Dockerfile:
FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortunes -a | cowsay

The command run:
$ docker build -t docker-whale .

The first part of the output from the command:
[The Docker forums disallow me from including more than two links, so have to modify the output to not show the URLs as links. So I’ve replaced http:// with LINK/]

Sending build context to Docker daemon 2.048 kB
Step 1 : FROM docker/whalesay:latest
—> 6b362a9f73eb
Step 2 : RUN apt-get -y update && apt-get install -y fortunes
—> Running in 9542e94271ab
Err LINK/archive.ubuntu.com trusty InRelease

Err LINK/archive.ubuntu.com trusty-updates InRelease

Err LINK/archive.ubuntu.com trusty-security InRelease

Err LINK/archive.ubuntu.com trusty Release.gpg
Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) [IP: 2001:67c:15
60:8001::11 80]
Err LINK/archive.ubuntu.com trusty-updates Release.gpg
Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) [IP: 2001:67c:15
60:8001::11 80]
Err LINK/archive.ubuntu.com trusty-security Release.gpg
Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) [IP: 2001:67c:15
60:8001::11 80]
[Many more lines of output with similar errors]

In case it is relevant here are the changes I made to /var/lib/boot2docker/profile with the internal names of the proxy replaced with XXX:
export "HTTP_PROXY=XXX-proxy.XXXXX.com:80"
export "HTTPS_PROXY=XXX-proxy.XXXXX.com:80"
export “NO_PROXY=192.168.99.,.local,169.254/16,.example.com,192.168.59.

I did some further testing and it does look like a proxy issue and not an IPv6 issue.
I used putty to ssh to the docker VM on my laptop (Boot2Docker version 1.11.2).
I then did a WGET without specifying a proxy and it timed out. I added the proxy and it connected and downloaded successfully from the host in question. Here it is with the internal proxy details X’ed out.

docker@default:~$ wget archive.ubuntu.com
Connecting to archive.ubuntu.com (91.189.88.152:80)
wget: download timed out
docker@default:~$ sudo env http_proxy=XXX-proxy.YYYYYY.com:80 wget archive.ubuntu.com
Connecting to XXX-proxy.YYYYYY.com:80 (ddd.dd.dd.ddd:80)
index.html 100% |***********************************************************************************************************************************| 696 0:00:00 ETA
docker@default:~$

That would imply to me that the proxy lines I specified in /var/lib/boot2docker/profile are not being used by docker. I’ll do some more digging to see why that might be.

They apply to the Docker daemon’s network connections, like docker pull commands, but they don’t apply to any code that’s running in containers, including docker build steps.

If you’re running a pre-existing container, you could docker run -e http_proxy=... to set a required environment variable. Dockerfiles must specially be set up to support proxies; docker build | Docker Documentation is probably a good starting point.

Thanks to comments from @dmaze I was finally able to get this to work using the following build command:
docker build --build-arg http_proxy=http://rmdc-proxy.oracle.com:80 -t docker-whale .

Originally I followed the example in the build CLI reference sited above by @dmaze:
docker build --build-arg HTTP_PROXY=http://10.20.30.2:1234 .
It took me quite a while to figure out that apt-get uses http_proxy, and ignores HTTP_PROXY. Once I switched to lower case then it worked.

The Dockerfile reference indicates that an ARG command is predefined for both HTTP_PROXY and http_proxy as well as the other similar environment variables: https_proxy, no_proxy, etc. I tried to figure out how to pass both HTTP_PROXY and http_proxy in the build statement, but no matter what I tried I get the error:
C:\dev\tools\DockerToolbox\docker.exe: “build” requires 1 argument.

I could not find an example or an explanation for how to set multiple --build-arg name=value pairs. If someone could provide a working example of this syntax that would help. I’d like to standardize on a build syntax that handles upper and lower case usage of these networking environment variables.

Thanks for the pointers.

Not sure what I did wrong last night, but I tried again today and was able to specify multiple --build-arg parameters like this:

docker build --build-arg HTTP_PROXY=http://XXX-proxy.YYYYYY.com:80 --build-arg http_proxy=http://XXX-proxy.YYYYYY.com:80 -t docker-whale .

Sorry for the confusion.

I tried this also. But it didn’t work for me.

Error logs:

sudo docker build -t rohit/dockerfile:v2 .
Sending build context to Docker daemon 2.048 kB
Step 1/2 : FROM ubuntu:16.04
—> 0ef2e08ed3fa
Step 2/2 : RUN apt-get update && apt-get upgrade -y && apt-get install -y software-properties-common && add-apt-repository ppa:webupd8team/java -y && apt-get update && echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && apt-get install -y oracle-java8-installer && apt-get clean
—> Running in 914b0b5f239d
Err:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Temporary failure resolving ‘archive.ubuntu.com

Any suggestions?