Run Docker from Behind Proxy

Run Docker from Behind Proxy

Configuring the Proxy Settings

OS X

Follow the instructions on the Setup Docker on OS X. Past the docker run hello-world step.

From the installation documentation we know that docker-machine actually runs in a VirtualBox VM within OS X, wrapping and hiding the older boot2docker code. So no existing proxy configuration settings apply, and you have to duplicate them as described next.

$ docker-machine ssh default

Now the command prompt will say something like:

docker@default:~$

We need root access:

$ sudo -s

Now the command prompt will say something like:

root@default:/home/docker#

Now configure the proxy:

echo "export HTTP_PROXY=http://<proxy_address>:[port]" >> /var/lib/boot2docker/profile
echo "export HTTPS_PROXY=http://<proxy_address>:[port]" >> /var/lib/boot2docker/profile

For verification:

# cat /var/lib/boot2docker/profile

Exit out of ssh session:

# exit
$ exit

Restart docker-machine:

$ docker-machine restart default

Ubuntu

Execute following command:

$ sudo echo "export HTTP_PROXY=http://<proxy_address>:[port]" >> /etc/default/docker
$ sudo echo "export HTTPS_PROXY=http://<proxy_address>:[port]" >> /etc/default/docker

Restart Docker

$ sudo service docker restart

CentOS 6

Execute following command:

$ sudo echo "export HTTP_PROXY=http://<proxy_address>:[port]" >> /etc/sysconfig/docker
$ sudo echo "export HTTPS_PROXY=http://<proxy_address>:[port]" >> /etc/sysconfig/docker

CentOS 7

Execute following command to create docker.service.d folder and edit http-proxy.conf file:

$ sudo mkdir /etc/systemd/system/docker.service.d
$ sudo vim /etc/systemd/system/docker.service.d/http-proxy.conf

Now configure the proxy:

[Service]
Environment="HTTP_PROXY=http://<proxy_address>:[port]"
Environment="HTTPS_PROXY=http://<proxy_address>:[port]"

Reload daemon and restart Docker:

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

For verification:

$ sudo systemctl show docker --property Environment
0.00 avg. rating (0% score) - 0 votes