41

I have docker daemon running on my Ubuntu 16.4 server

my server details:

No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 17.04 Release: 17.04 Codename: zesty

I'm receiving the following error:

aa@aaa-VirtualBox:/etc/default$ 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: lookup registry-1.docker.io: no such host.
See 'docker run --help'.

I have set the http_proxy and the https_proxy beacuse i'm behind a corp proxy/firewall

Any clues how I can fix this issue?

Tal Avissar
  • 10,088
  • 6
  • 45
  • 70

9 Answers9

46

You need to set the proxy for Docker daemon also using environment variable. Docker run is also doing docker pull since the image doesn't exists. In your case the proxy is only applied to the docker run command, which delegates to the docker daemon which is running without proxy.

Create a file named /etc/systemd/system/docker.service.d/10_docker_proxy.conf with below content

[Service]
Environment=HTTP_PROXY=http://1.1.1.1:111
Environment=HTTPS_PROXY=http://1.1.1.1:111

Make sure to update the proxy as per the ones you have 1.1.1.1:111 is just an example

Then execute below commands to restart docker

sudo systemctl daemon-reload
sudo systemctl restart docker

Now use your docker run command and it should work

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
  • finally this works, but not sure why this solution (https://docs.docker.com/network/proxy/) doesn't work. – BMW Apr 30 '19 at 03:55
  • @Tarun Lalwani, could you have a look at my question here: https://stackoverflow.com/questions/57792954/cannot-download-docker-images-no-such-host. I don't know the full path of docker.service.d on my windows PC. Thanks. – w0051977 Sep 04 '19 at 17:11
  • 1
    In my case, docker was working fine and this error popped up all of a sudden. A simple restart with `sudo systemctl restart docker` fixed it. – belvederef Nov 07 '20 at 10:16
  • After doing this i'm getting Get https://k8s-master:5000/v1/_ping: proxyconnect tcp: dial tcp 1.1.1.1:111: i/o timeout – Yogesh Bombe Jun 07 '22 at 19:36
  • In my case, based on this solution i added HTTP_PROXY and HTTPS_PROXY as an environment variable in my windows 10 PC. The values in it were configured to localhost:3129 where px proxy was running on port number 3129 . I was able to later pull images. – Ravikiran R Feb 18 '23 at 15:09
19

Things you can try:

a) Add nameserver 8.8.8.8

Method #1

docker-machine ssh default
sudo vi /etc/resolv.conf
//change nameserver to 8.8.8.8

Then restart the server using

service docker restart

Note: If you don't have docker-machine installed, you can follow instructions here to install it. It comes with Windows and Mac but is available for install on Linux manually.

Method #2

Edit /etc/docker/daemon.json Or "provide a JSON configuration in the preference panel" with the following information:

{ "dns" : [ "8.8.8.8", "8.8.4.4" ]}

Then restart the server using

service docker restart

b) Setup Proxy

Method #1

Edit your proxy configuration as Tarun Lalwani suggested.

Edit /etc/default/docker and add:

export http_proxy='http://username:password@proxy-host:proxy-port'
export https_proxy='https://username:password@proxy-host:proxy-port'

Then restart the server using

service docker restart

Method #2

Source: https://github.com/moby/moby/issues/32270#issuecomment-340709035

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

    mkdir -p /etc/systemd/system/docker.service.d
    # For HTTP Proxy:
    vim /etc/systemd/system/docker.service.d/http-proxy.conf
    # For HTTPS Proxy:
    vim /etc/systemd/system/docker.service.d/https-proxy.conf
    
  2. Then add below content with proxy settings with it (Change to "HTTPS" for https)

    [Service]
    Environment="HTTP_PROXY=http://<allowed_proxy_ipv4_address>:<proxy_port_num>/"
    [Service]
    
  3. sudo systemctl daemon-reload

  4. sudo systemctl restart docker
  5. Verify that the configuration has been loaded: systemctl show --property=Environment docker

c) Reinstall Docker

Unfortunately the last resort, could work. Check out these github pages for more suggestions:

For me, setting up the proxy using the systemctl method was the only thing that worked.

Katie
  • 45,622
  • 19
  • 93
  • 125
12

I bumped into this error and was able to resolve by a simple restart:

sudo service docker restart
5

I solve the error changing DNS server by 8.8.8.8 - Ubuntu 18.04.3 LTS

1- Open the Ubuntu System Settings and Navigate to Network

enter image description here

2- Click the on the setting button next to the Network name in the list to which you are connected.

3- New Window will open with a lot number of tabs, with one of them with the label of “IPv4”.

enter image description here

4- Upon opening the “IPv4” Tab you will find a Field of “DNS”. Here you can write the DNS server

enter image description here

If you want to use more than one DNS, then you can enter and separate them with a comma.

4

I tried many of the above answers, but to no avail.

Finally, this approach worked for me:

docker logout
docker login

I have no idea why though.

not2savvy
  • 2,902
  • 3
  • 22
  • 37
2

Go to Docker Settings -> Proxies -> Manual proxy configuration.

Set the proxy details in the input and apply.

Restart the docker. This will fix the issue.

http://19.12.1.40:83

1

Simplified detailed solution in case you are having this problem in windows is as below: right click on network open network and internet setting In advanced network setting, click on change adapter options right click on your network or wifi connection click on properties in Networking tab click on Internet protocal version 4 (TCP/IPv4) or ipv6 In general, click on use the following DNS server address and add 8.8.8.8 on preferred DNS server

10raw
  • 506
  • 12
  • 26
1

FOr windows going to resoureces -Network and changing DNS to 8.8.8.8 did the trick. ALso make sure to restart after chaning. enter image description here

10raw
  • 506
  • 12
  • 26
0

Configure Docker to start on boot

sudo systemctl enable docker
Annika
  • 1
  • 1