43

Looking at docs there is no instruction on how to run it behind a proxy. https://docs.docker.com/installation/ubuntulinux/

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

 export http_proxy="http://127.0.0.1:3128/"
 export https_proxy="http://127.0.0.1:3128/"
 export HTTP_PROXY="http://127.0.0.1:3128/"
 export HTTPS_PROXY="http://127.0.0.1:3128/"

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.

sesteva
  • 1,716
  • 2
  • 16
  • 17
  • 1
    Inside the container `127.0.0.1` is going to point at the container itself. Probably not the IP you want here. – Thomas Orozco Oct 24 '14 at 15:20
  • For future readers, it would be helpful to clarify in the question what kind of proxy and the purpose. Because running a docker instance behind a reverse proxy is common, and it's not very obvious what the OP is trying to achieve. Perhaps: "I want to be able to perform HTTP requests from the docker container, but need to go through a web proxy". – jdhildeb Apr 30 '18 at 16:38
  • Check this link, it has every possible way specified very clearly: https://movidius.github.io/ncsdk/docker_proxy.html – subtleseeker Mar 12 '19 at 19:19

9 Answers9

150

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

#
# THIS FILE DOES NOT APPLY TO SYSTEMD
#
#   Please see the documentation for "systemd drop-ins":
#   https://docs.docker.com/engine/articles/systemd/
#

.......
# If you need Docker to use an HTTP proxy, it can also be specified here.
export http_proxy="http://web-proxy.corp.xxxxxx.com:8080/"
export https_proxy="https://web-proxy.corp.xxxxxx.com:8080/"
......

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
[Service]
Environment="HTTP_PROXY=https://web-proxy.corp.xxxxxx.com:8080/"
Environment="HTTPS_PROXY=https://web-proxy.corp.xxxxxx.com:8080/"
Environment="NO_PROXY=localhost,127.0.0.1,localaddress,.localdomain.com"

(3) Flush changes:

systemctl daemon-reload

(4) Restart Docker:

systemctl restart docker

Official Reference

yesnik
  • 4,085
  • 2
  • 30
  • 25
Nan Xiao
  • 16,671
  • 18
  • 103
  • 164
25

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
Lord of freaks
  • 439
  • 5
  • 8
9

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

https_proxy="http://127.0.0.1:3128"
http_proxy="http://127.0.0.1:3128"
ftp_proxy="http://127.0.0.1:3128"
no_proxy="127.0.0.1/8, localhost, 192.168.0.0/16"

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:

EnvironmentFile=/etc/environment

And then:

sudo systemctl daemon-reload
sudo systemctl restart docker.service
subtleseeker
  • 4,415
  • 5
  • 29
  • 41
z00110010
  • 91
  • 1
  • 2
  • 3
    I like this method the best. However, before restarting the service I had to run 'systemctl daemon-reload' – akirekadu Mar 02 '19 at 02:02
4

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,127.0.0.1

Mrinal Deo
  • 171
  • 1
  • 8
2

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.

Jian Wang
  • 65
  • 5
1

According to the Docs

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

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://127.0.0.1:3001",
     "noProxy": "*.test.example.com,.example2.com"
   }
 }
}
Anton
  • 5,831
  • 3
  • 35
  • 45
0

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

Quanlong
  • 24,028
  • 16
  • 69
  • 79
0

This is an old thread but none of the solutions here worked for me because I am not running docker desktop. What worked is the one in the documentation. You need to make a file /etc/systemd/system/docker.service.d/http-proxy.conf and specify proxies there

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80"
0

The OP setup the proxy to docker but he is using ubuntu inside docker, He want to run apt-get, for that he need to setup the proxy again for apt-get

Run inside your ubuntu docker container the following command

nano /etc/apt/apt.conf

and then edit inside it the proxy configuration:

Acquire::http::proxy "http://proxy.svr.com:1234";
Acquire::https::proxy "https://proxy.svr.com:1234";

As mention on other anwers, if your proxy require auth and your password have special characters, you need to URL escaped then.

There is an example for auth:

username: u$3er_n@m3
password: p@$$w+rd
domain: domain

Acquire::http::proxy "http://domain%5Cpega%5Cu%243er_n%40m3:p%40%24%24w%2Brd@proxy.svr.com:1234";
Acquire::https::proxy "https://domain%5Cpega%5Cu%243er_n%40m3:p%40%24%24w%2Brd@proxy.svr.com:1234";
klys
  • 343
  • 1
  • 3
  • 15