1.Create a systemd drop-in directory for the docker service:
$ sudo mkdir -p /etc/systemd/system/docker.service.d
2.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://<username>:<password>@<host>:<port>"
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=http://<username>:<password>@<host>:<port>"
3.Flush changes:
$ sudo systemctl daemon-reload
4.Restart Docker:
$ sudo systemctl restart docker
Docker has published the above info with some additional info at https://docs.docker.com/config/daemon/systemd/