Sometimes Docker users are unable to download Docker images behind a proxy due to issues with the Docker proxy settings.
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:
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:
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
Finally, we restart the Docker by running the below command:
$ sudo systemctl restart docker
Finally, this fixed the Docker error.