Cannot download Docker images behind a proxy - Fix it Now








Sometimes Docker users are unable to download Docker images behind a proxy due to issues with the Docker proxy settings.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to resolve such Docker-related issues while troubleshooting Docker issues.

In this context, we shall look into method to fix this Docker error.


What to do when we Cannot download Docker images behind a proxy ?

We had a customer who installed Docker on his Ubuntu server. Then he tried running the below command:

$ sudo docker pull busybox

As a result, he received the below error:

Pulling repository busybox
2021/03/16 09:37:07 Get https://index.docker.io/v1/repositories/busybox/images: dial tcp: lookup index.docker.io on 127.0.1.1:53: no answer from server

In order to resolve this problem, we first create a systemd drop-in directory for the Docker service by running the below command.

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

Next, we 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/"

Note: In case, if you have internal Docker registries that you need to contact without proxying you can specify them via the NO_PROXY environment variable:

Environment="HTTP_PROXY=http://proxy.example.com:80/"
Environment="NO_PROXY=localhost,127.0.0.0/8,docker-registry.somecorporation.com"

After that, we flush the changes by running the below command:

$ sudo systemctl daemon-reload

Then we verify if the configuration is loaded or not. For that, we run the below command:

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

Finally, we restart the Docker by running the below command:

$ sudo systemctl restart docker

Finally, this fixed the Docker error.


[Need urgent assistance in fixing Docker errors? – We're available 24*7. ]



Conclusion

This article covers the error, Cannot download Docker images behind a proxy. 

You can fix this docker issue by doing the following:

1. In the file /etc/default/docker, add the line:

export http_proxy='http://<host>:<port>'

2. Restart Docker:

$ sudo service docker restart


Also, you can Follow the steps given below to fix this docker error:

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

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

2. Create a file called /etc/systemd/system/docker.service.d/http-proxy.conf and add the HTTP_PROXY env variable:

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

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

Environment="HTTP_PROXY=http://proxy.example.com:80/"
Environment="NO_PROXY=localhost,127.0.0.0/8,docker-registry.somecorporation.com"

4. Flush changes:

$ sudo systemctl daemon-reload

5. Verify that the configuration has been loaded:

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

6. Restart Docker:

$ sudo systemctl restart docker

For Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on LinuxAPT.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com