This blog post provides a little cheat sheet on running a Linux host with or without a Docker client behind HTTP proxies. For Ubuntu and similar Linux distributions, we will also show how to detect the proxy available and adapt the proxy settings accordingly. This comes handy, if you are a road warrior that often switches from a network with proxy and a network with no or a different proxy without restarting the Linux host (e.g. a notebook you only place in standby or hibernate mode). This is not tested for other Linux distributions, but might work there as well.


For setting the HTTP proxy settings of a Docker host, you can try to follow this official docker instructions on how to handle HTTP proxy configuration. As fas as I remember, those instructions have not worked on my Ubuntu Docker host (I cannot test it easily in the moment). This is, why I have dug deeper into that matter and why I have come up with this little cheat sheet.

The steps needed to connect a Docker client to Docker hub via a HTTP proxy seem to depend on the Linux distribution used. I have tested the HTTP configuration for Ubuntu and CoreOS. For most Debian-based Linux distributions, I guess, you can follow the same instructions as you find here for Ubuntu. In any case, check out the various answers and comments in this StackOverflow question, if the instructions below do not work. Feedback is highly welcome.


Manual Settings

First let us detect, whether sudo is needed:

sudo echo hello > /dev/null 2>&1 && SUDO=sudo

On Ubuntu (tested with 14.04 LTS), we need to configure the file /etc/default/docker.

$SUDO vi /etc/default/docker

add proxy, if needed

export http_proxy=''
export https_proxy=''

In case your HTTP proxy requires authentication, try with:

export http_proxy=''
export https_proxy=''

In any case, you need to exchange the values for yourname, yourpassword, the proxy FQDN or IP address ( and the TCP port (8080) by the values that apply to your environment.


$SUDO restart docker

then you can test it with:

$SUDO docker search ubuntu

should work now. If the proxy configuration is not correct, you will encounter an error message that looks like similar to following line:

Get dial tcp: lookup on no answer from server

Automated Settings

If you are running a Linux host on your notebook (with or without Docker) and if you often change the network environment without rebooting the Linux machine, you might find it handy to set the proxy automagically just by typing p<Enter> . This can be done using my linux_set_proxy git repository like follows:

git clone
cd linux_set_proxy; sudo ./

Then each time the proxy has changed, you just type:

source proxy <proxy-name_or_IP> <proxy_port>

If the proxy is not available, the proxy settings are reset automatically.

Simplified Usage

Consider you are switching between network environments with no proxy,,, and the ports 81, 8080 and 81, respectively, you just need to define an alias like follows:

alias p=source proxy 81 || source proxy 8080 || source proxy 81

If you want this definition to persist, you can add this line to your ~/.bashrc file (if bash is your favorite Linux shell).

Next time, the proxy has changed, you just need to type


and the program will test, which proxy is available and

  1. adjust the settings of the HTTP_PROXY, HTTPS_PROXY environment variables, and
  2. change the Docker configuration file and restart Docker, making sure that any subsequent docker command are using the right HTTP proxy settings


Manual Settings

First let us detect, whether sudo is needed:

sudo echo hello > /dev/null 2>&1 && SUDO=sudo

For CoreOS, we can follow the official docker instructions:

$SUDO mkdir /etc/systemd/system/docker.service.d
$SUDO vi /etc/systemd/system/docker.service.d/http-proxy.conf

and add something like:


(replace the URL, so it fits to your environment)


$SUDO reboot

or if you do not want to reboot, try:

$SUDO sysctl docker restart

Automated Settings

Not supported yet.

Docker Host DNS Configuration for Vagrant

On a Vagrant based Ubuntu system, I had a problem resolving FQDNs to IP addresses. The solution was to add the following three lines into the Vagrantfile. The fix is described here:

# The fix is described on
config.vm.provider "virtualbox" do |v|
  v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]