10

I need setup the corporation proxy in order Docker can download the images from public registry.

$ sudo docker run hello-world 
Unable to find image 'hello-world:latest' locally 
Pulling repository docker.io/library/hello-world 
Error while pulling image: Get https://index.docker.io/v1/repositories/library/hello-world/images: dial tcp: lookup index.docker.io: no such host

I'm using Ubuntu 12.04 machine. I have found this answer but systemctl is not present in Ubuntu 12.04. How can I do this?

Thanks.

Sufiyan Ghori
  • 18,164
  • 14
  • 82
  • 110
Héctor
  • 24,444
  • 35
  • 132
  • 243
  • Thanks. It works. Post it as answer and I will accept – Héctor Jan 18 '16 at 11:06
  • Possible duplicate of [Cannot download Docker images behind a proxy](https://stackoverflow.com/questions/23111631/cannot-download-docker-images-behind-a-proxy) – andolsi zied Feb 01 '18 at 09:40

6 Answers6

4

From Docker official documentation,

Create a systemd drop-in directory for the docker service:

$ sudo mkdir -p /etc/systemd/system/docker.service.d

Create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:

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

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:

[Service]
Environment="HTTPS_PROXY=https://proxy.example.com:443/"

If you have internal Docker registries that you need to contact without proxying you can specify them via the NO_PROXY environment variable:

[Service]    
Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"

Or, if you are behind an HTTPS proxy server:

[Service]    
Environment="HTTPS_PROXY=https://proxy.example.com:443/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"

Flush changes:

$ sudo systemctl daemon-reload

Restart Docker:

$ sudo systemctl restart docker

Verify that the configuration has been loaded:

$ systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/

Or, if you are behind an HTTPS proxy server:

$ systemctl show --property=Environment docker
Environment=HTTPS_PROXY=https://proxy.example.com:443/
Sufiyan Ghori
  • 18,164
  • 14
  • 82
  • 110
3

I was getting the following error while trying to run the hello-world container

$docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp 34.205.194.204:443: getsockopt: no route to host.

I tried the steps in the following link which worked for me with respect to HTTPS or HTTP configuration

https://docs.docker.com/engine/admin/systemd/#httphttps-proxy

2

On CentOS, what works for me is to add this line to /etc/sysconfig/docker:

http_proxy=your_proxy:port
Hoang Huynh
  • 1,384
  • 2
  • 16
  • 33
1

For Ubuntu only

Edit /etc/defaults/docker.io and add the following lines:

export http_proxy='http://user:password@proxy-host:proxy-port'

Then restart docker daemon:

sudo service docker.io restart
Sufiyan Ghori
  • 18,164
  • 14
  • 82
  • 110
Héctor
  • 24,444
  • 35
  • 132
  • 243
  • There is no `/etc/defaults/` directory. Maybe you mean `/etc/default/` . Also there is no `docker.io` service, but maybe you have a different Ubuntu version (I have bionic LTS 18.04.4) – Dan Anderson Feb 05 '20 at 00:21
1

You need to set proxy for both docker server (docker-machine) and docker client (docker).

Set proxy for docker-machine: I think you can specify this when creating the machine, see docker/toolbox#102 (comment)

docker-machine create -d virtualbox \
--engine-env HTTP_PROXY=http://example.com:8080 \
--engine-env HTTPS_PROXY=https://example.com:8080 \
--engine-env NO_PROXY=example2.com \
default

Set Proxy for docker (client)

Windows

set http_proxy=http://example.com:8080
set https_proxy=https://example.com:8080

Linux

export http_proxy=http://example.com:8080
export https_proxy=https://example.com:8080
PratikShah
  • 153
  • 1
  • 7
-1

In-spite of adding the proxy, docker version "18.06.0" dosn't work, however the lower version of the docker works fine.

Edit 1: Re-installing docker-ce will work !!

Aman Dalmia
  • 83
  • 2
  • 9