Proxy for Docker daemon

When using Docker, actions like pulling images are performed by the Docker daemon and do not use your shell’s environment variables. To configure proxy settings for the Docker daemon:

Create directory /etc/systemd/system/docker.service.d for Docker proxy settings config file. Then create /etc/systemd/system/docker.service.d/http-proxy.conf with the following contents (replace proxy.server and port):

[Service]
Environment="HTTP_PROXY=http://proxy.server:port"
Environment="HTTPS_PROXY=http://proxy.server:port"
Environment="NO_PROXY=localhost,127.0.0.1"

Apply settings and restart Docker:

sudo systemctl daemon-reload
sudo systemctl restart docker

(Check the settings using systemctl show --property=Environment docker).

More info: https://docs.docker.com/config/daemon/systemd/#httphttps-proxy

Proxy for Docker build and Docker Compose

If you’re building Docker images with docker build or docker-compose, you will want to configure proxy settings for the build process. Despite the fact that Docker daemon has the correct proxy settings, during the build process commands that update the image being built (i.e. apk updateapt-get update etc.) will fail without this step.

For the user that will be building images, create ~/.docker/config.json with the following contents (replace proxy.server and port):

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "<http://proxy.server>:port",
     "httpsProxy": "<http://proxy.server>:port",
     "noProxy": "localhost,127.0.0.1"
   }
 }
}

More info: https://docs.docker.com/network/proxy/