How to use "docker login" with a proxy?

Viewed 3207

I am trying to run docker login, but I am getting the following error:

Error response from daemon: Get "https://[removed_id_for_stackoverflow].dkr.ecr.us-east-1.amazonaws.com/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

I have the following within my ~/.bash.rc file:

export HTTP_PROXY="http://192.168.1.1:8080"
export HTTPS_PROXY="http://192.168.1.1:8080"
export https_proxy="http://192.168.1.1:8080"
export https_proxy="http://192.168.1.1:8080"
export ftp_proxy="http://192.168.1.1:8080"
export no_proxy="localhost,127.0.0.1,::1"

If I run curl https://www.google.com then I can get a valid response, confirming that these settings work. If I remove these environment variables, then my curl command no longer works, so I'm pretty sure it's configured correctly from an environment variable perspective.

According to Docker Hub login behind a proxy, you can just pass the proxy options into the command line when running docker login; however, I've tried this and the results are the same. See the example below:

root@my-host:~/.docker# HTTPS_PROXY=http://192.168.1.1:8080 aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $(aws sts get-caller-identity --output text --query 'Account').dkr.ecr.us-east-1.amazonaws.com >/dev/null
Error response from daemon: Get "https://[removed_for_stack_overflow].dkr.ecr.us-east-1.amazonaws.com/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

I tried changing the proxy settings to appear before docker login instead of aws, tried using HTTP_PROXY instead of HTTPS_PROXY, but still no luck. Doesn't seem to matter in which order the proxy options are specified.

I also have a file called ~/.docker/config.json that contains the following proxy information:

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://192.168.1.1:8080",
     "httpsProxy": "http://192.168.1.1:8080"
   }
 }
}

Even with this setting, docker login doesn't appear to be working still and provides the same results.

1 Answers

The correct way to configure proxy for docker daemon is recorded here, I extract some of contents for your infomation:

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

    sudo mkdir -p /etc/systemd/system/docker.service.d

  2. Create a file named /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY/HTTPS_PROXY environment variable:

    Config example:

    [Service]
    Environment="HTTP_PROXY=http://proxy.example.com:80"
    Environment="HTTPS_PROXY=https://proxy.example.com:443"
    Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp"
    
  3. Flush changes and restart Docker

    sudo systemctl daemon-reload
    sudo systemctl restart docker
    
  4. Verify that the configuration has been loaded and matches the changes you made, for example:

    sudo systemctl show --property=Environment docker

Related