docker image build command fails with "(Client.Timeout exceeded while awaiting headers)"

14,686

After a much trail and error and lot of googling... finally I was able to make docker work behind my office VPN.

And for the benefit of people who might be facing issue similar to mine, below are the steps I performed to resolve the issue:

Three different places where I had modified the proxy value and that got the issue fixed.

  1. /etc/systemd/system/docker.service.d/http-proxy.conf Check if this file exists in your setup, and if it does not create this file and perform below steps:

    • Open the file and add below statements in it and save:

      [Service]
      Environment="HTTP_PROXY=http://proxyHost:proxyPort"
      Environment="HTTPS_PROXY=http://proxyHost:proxyPort"
      Environment="NO_PROXY=localhost,127.0.0.1"
      
    • Flush the above changes by running below command:

      sudo systemctl daemon-reload
      
    • Verify that the above changes have been taken affect by running the command below. This should print the Environment variable value:

      sudo system ctl show --property Environment docker
      
    • Once you successfully verify that the variable is set, restart the docker service by running below command:

      sudo systemctl restart docker
      
  2. ~/.docker/config.json: Add the json property shown below to the existing properties in the file.

        "proxies": {
          "defaults": {
            "httpProxy":"http://proxyHost:proxyPort",
            "httpsProxy":"http://proxyHost:proxyPort"
          }
        }
    
  3. /etc/default/docker : Open or create this file with this content:

    export http_proxy='http://proxyHost:proxyPort'
    export https_proxy='http://proxyHost:proxyPort'
    

Once I had all the above changes done, I rebooted my setup and then docker image pull and other docker commands started working without issues.

Note: All the above changes may not be required but for me above changes made sure that docker works after I connect to my VPN.

Share:
14,686

Related videos on Youtube

Santosh Giri Govind Marthi
Author by

Santosh Giri Govind Marthi

Updated on September 18, 2022

Comments

  • Santosh Giri Govind Marthi
    Santosh Giri Govind Marthi over 1 year

    I am new to docker and Ubuntu 16.04 OS as well. My configuration is as follows :

    Ubuntu:

    $lsb_release -a
    
    No LSB modules are available.
    
    Distributor ID: Ubuntu
    
    Description:    Ubuntu 16.04.5 LTS
    
    Release:    16.04
    
    Codename:   xenial
    

    Docker :

    $ docker info
    
    Containers: 2
    
     Running: 0
    
     Paused: 0
    
     Stopped: 2
    
    Images: 5
    
    Server Version: 18.09.0
    
    Storage Driver: overlay2
    
     Backing Filesystem: extfs
    
     Supports d_type: true
    
     Native Overlay Diff: true
    
    Logging Driver: json-file
    
    Cgroup Driver: cgroupfs
    
    Plugins:
    
     Volume: local
    
     Network: bridge host macvlan null overlay
    
     Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk 
    syslog
    
    Swarm: inactive
    
    Runtimes: runc
    
    Default Runtime: runc
    
    Init Binary: docker-init
    
    containerd version: c4446665cb9c30056f4998ed953e6d4ff22c7c39
    
    runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
    
    init version: fec3683
    
    Security Options:
    
     apparmor
    
     seccomp
    
      Profile: default
    
    Kernel Version: 4.15.0-42-generic
    
    Operating System: Ubuntu 16.04.5 LTS
    
    OSType: linux
    
    Architecture: x86_64
    
    CPUs: 4
    
    Total Memory: 15.4GiB
    
    Name: smarthi-ORADEV
    
    ID: 3OIT:CLN4:HNUU:W4SG:Z6OZ:NRRV:WSSN:E7PO:A2ZZ:XGYI:CXUZ:VBUD
    
    Docker Root Dir: /var/lib/docker
    
    Debug Mode (client): false
    
    Debug Mode (server): false
    
    Username: bluesangig
    
    Registry: https://index.docker.io/v1/
    
    Labels:
    
    Experimental: false
    
    Insecure Registries:
    
     127.0.0.0/8
    
    Live Restore Enabled: false
    
    Product License: Community Engine
    
    WARNING: No swap limit support
    

    I am connect to office VPN network and all my accesses to office and internet are working fine with my Network proxy configuration done in my laptop.

    Even docker container run commands are also working fine.

    But when I try to do docker image build using a docker file whose content is:

    FROM busybox RUN echo "building simple docker image" CMD [echo, "hello container"]

    I am getting below error message:

    $ docker image build -t testimg .
    Sending build context to Docker daemon  2.048kB
    Step 1/3 : FROM busybox
    Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
    

    I had searched a bit and found that we may need to set the proxy in the ~/.docker/config.json file, and I had added the proxy entries as mentioned in the issue

    Even after adding the entries as suggested in the above issue, I still face the same issue.

    I am little clueless now on how to solve this issue with docker image build. Any help would be greatly appreciated.

  • Santosh Giri Govind Marthi
    Santosh Giri Govind Marthi over 5 years
    thank you for the reply, but I donot see /etc/default/docker file in my system. I see this issue everytime I reboot my machine. And one of my friends has suggested to to add "Acquire::http::proxy "<proxyHost>:<proxyPort>/"; in /etc/apt/apt.conf file... If I do that I see that things started working. But today even that solution is not working... Any suggestions on how to make the network stable on my system? Please help
  • Santosh Giri Govind Marthi
    Santosh Giri Govind Marthi over 5 years
    I had even tried adding the above file with the export statmements in it: $ cat /etc/default/docker export http_proxy='www-proxy.us.oracle.com:80' export https_proxy='www-proxy.us.oracle.com:80' Still I see the same issue occurring: $ docker container run hello-world Unable to find image 'hello-world:latest' locally docker: Error response from daemon: Get registry-1.docker.io/v2: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers). See 'docker run --help'. Any further help with this regards?
  • java4africa
    java4africa over 4 years
    On Linux I had to use lower case names for the proxy to work. So in /etc/systemd/system/docker.service.d/http-proxy.conf I had to use "Environment=http_proxy=http...", with lower case and no quotes.