Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apt-get in docker behind corporate proxy

I'm attempting to set up a development environment behind a corporate proxy server with Docker. Try as I might, I cannot get the docker container to talk to the proxy server.

The proxy server and apt-get work fine on the host, which is Ubuntu 12.04

The first thing done in the Dockerfile is attempting to set up the proxy variables:

FROM ubuntu
RUN echo 'Acquire::http { Proxy "http://my.proxy.net:8000"; };' >> /etc/apt/apt.conf.d/01proxy
ENV HTTP_PROXY http://my.proxy.net:8000
ENV http_proxy http://my.proxy.net:8000
ENV HTTPS_PROXY https://my.proxy.net:8000
ENV https_proxy https://my.proxy.net:8000
RUN apt-get update && apt-get install -y build-essential

It pulls the image fine, set the variables, but when it gets to apt-get update, it tries for a little while and then fails with:

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease  
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease  
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/InRelease  
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg  Could not resolve 'my.proxy.net'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg  Could not resolve 'my.proxy.net'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg  Could not resolve 'my.proxy.net'
W: Some index files failed to download. They have been ignored, or old ones used instead.

These variables I have set up are consistent with the host linux install (Ubuntu 12.04 on VirtualBox, if that matters)

I also have /etc/default/docker set up with:

export http_proxy="http://my.proxy.net:8000"
export http_proxy="https://my.proxy.net:8000"

Any thoughts?

UPDATE:

It looks like this is an issue with DNS, not necessarily the proxy server. The host /etc/resolve.conf contains:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1
search dhcp.mycompany.com

The host is a virtualbox vm running on a Windows 7 box, and I've found various half-baked solutions that mostly seem to not work. No matter what I try, I can't get it to resolve the hostname of the proxy server

like image 362
DVG Avatar asked Apr 14 '15 14:04

DVG


People also ask

How do I set up a proxy server for Docker containers?

On the Docker client, create or edit the file ~/.docker/config.json in the home directory of the user which starts containers. Add JSON such as the following, substituting the type of proxy with httpsProxy or ftpProxy if necessary, and substituting the address and port of the proxy server. You can configure multiple proxy servers at the same time.

How do I set the HTTP_proxy environment variable for a docker service?

Create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable: Or, if you are behind an HTTPS proxy server, create a file called /etc/systemd/system/docker.service.d/https-proxy.conf that adds the HTTPS_PROXY environment variable:

What are some examples of Docker running processes?

A famous example would be running a java process, eg gradle. In most cases the proxy configuration for the docker daemon as well as the container runtime go hand in hand: When building images you probably need to access a docker registry as well as access web resources during the build time.

Is it painful to work behind a corporate proxy?

Working behind a corporate proxy can be a painful experience. Attempts to simply accessing web resources are spoiled. When it comes to docker there are a couple configuration options we should know of. In this post I’d like to give an overview of their effects and what to keep in mind.


1 Answers

The issue ended up being with DNS. Docker is running on Ubuntu, which is, itself, a Guest OS on VirtualBox. Due to it's own virutalizing mumbo jumbo, it assigned a nameserver of 127.0.0.1 in resolv.conf.

When this happens, Docker will assign itself a DNS nameserver of 8.8.8.8 (google's nameserver) since localhost refers to the docker container not the host.

To fix this, I went all the way out to Windows and ran

ipconfig /all

And got the IP address of my laptops DNS Servers. I added these to DOCKER_OPTS in the configuration file with --dns=my.dns.ip.address and restarted docker, and the other measures I took to get through the proxy worked fine.

like image 106
DVG Avatar answered Sep 20 '22 12:09

DVG