Docker Ubuntu Behind Proxy

Looking at docs there is no instruction on how to run it behind a proxy.

Reading on forums, the instruction is to update /etc/default/docker to export the proxy setup.

 export http_proxy=""
 export https_proxy=""
 export HTTP_PROXY=""
 export HTTPS_PROXY=""

Then we restart/start docker

 sudo service docker start

Inside a container, if I run 'apt-get', npm install, bower install I cant get through the proxy.

Not sure what I m missing.


Ubuntu 14.04 LTS

For Ubuntu 14.04 LTS who uses SysVinit, you should modify /etc/default/docker file:

# cat /etc/default/docker
# Docker Upstart and SysVinit configuration file

#   Please see the documentation for "systemd drop-ins":

# If you need Docker to use an HTTP proxy, it can also be specified here.
export http_proxy=""
export https_proxy=""

Then restart docker:

service docker restart
Ubuntu 16.04 LTS / Ubuntu 18.04 LTS

For Ubuntu 16.04 LTS who uses Systemd, you can follow this post:

(1) Create a systemd drop-in directory:

mkdir /etc/systemd/system/docker.service.d

(2) Add proxy in /etc/systemd/system/docker.service.d/http-proxy.conf file:

# cat /etc/systemd/system/docker.service.d/http-proxy.conf

(3) Flush changes:

systemctl daemon-reload

(4) Restart Docker:

systemctl restart docker

Official Reference

For Ubuntu 14.04.2 LTS Linux vagrant-ubuntu-trusty-64 3.13.0-54-generic #91-Ubuntu SMP Tue May 26 19:15:08 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Edit you /etc/default/docker file

sudo vim /etc/default/docker

Add this line at the bottom:

export http_proxy="http://PROXY_IP:PROXY_PORT"

Restart the docker service

sudo service docker restart

You can try to add lines in /etc/environment:

no_proxy=", localhost,"

it will be useful for all services on your Linux system

Then edit /lib/systemd/system/docker.service. In the end of the [Service] section, add line:


And then:

sudo systemctl daemon-reload
sudo systemctl restart docker.service

systemctl will have to installed, which can be problematic. In case /etc/systemd/system/docker.service.d/http-proxy.conf or /etc/default/docker solution does not work for you, simply use the below command:

docker build [OPTIONS] PATH --build-arg http_proxy=http://your.proxy:port --build-arg https_proxy=http://your.proxy:port --build-arg no_proxy=.internal.domain,localhost,

In Ubuntu 14.04 LTS:

An interesting issue about the HTTP_PROXY, HTTPS_PROXY is that: if your password has a special char like "$", "%", then it will not be processed correctly by the docker daemon when you execute command like: dock run xxx, you will encounter error. Then you can try to set the special char to others, good luck.

According to the Docs

Add to ~/.docker/config.json proxy configuration

     "httpProxy": "",
     "noProxy": "*,"

You should replace to your host IP or some public accessible IP

Need Your Help

How to automatically restart Tomcat7 on system reboots?

scripts init.d tomcat

I have installed Tomcat 7 on Ubuntu 12.04 LTS which runs on an Amzon EC2 instance. Now I wish tomcat should restart automatically on system reboot.

Deserializing JSON into an object with Json.NET

c# .net json serialization

I'm playing a little bit with the new StackOverflow API. Unfortunately, my JSON is a bit weak, so I need some help.