Docker - Set HTTP/HTTPS proxy

By xngo on October 1, 2019

Issue

After I installed Docker, I test run it and it is showing me the following error message:

/media/master/github>docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: x509: certificate is valid for xxxx.xx.xxxxx.xxx, not registry-1.docker.io.
See 'docker run --help'.

Solution

I got the error because I'm behind a proxy server. Therefore, to resolve this issue, I set the proxy configurations in Docker as follows.

  1. Create a systemd drop-in directory for the docker service:
$ mkdir -p /etc/systemd/system/docker.service.d
  1. Create a file called /etc/systemd/system/docker.service.d/http-proxy.conf and add the HTTP_PROXY environment variable:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
  1. Restart Docker:
systemctl daemon-reload
systemctl restart docker
  1. Verify that the configuration has been loaded:
$ systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/
  1. Test run Docker: Docker - Run hello-world - Output

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.