How to Solve Error Message http: server gave HTTP response to HTTPS client when running Docker command

Posted on

Introduction

This is an article where the main focus is how to solve an error message when executing a specific docker command. It is a command to build a Docker image by executing a Dockerfile. The content of the Dockerfile exist as follows :

FROM hub.docker.local:5000/centos

That file exist in ‘C:\mydocker-build’, so the following are the attempt for the executions :

C:\mydocker-build>docker build --tag hello-world:latest .
[+] Building 0.7s (3/3) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                   0.1s
 => => transferring dockerfile: 32B                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                      0.1s
 => => transferring context: 2B                                                                                                                                        0.0s
 => ERROR [internal] load metadata for hub.docker.local:5000/centos:latest                                                                                             0.5s
------
 > [internal] load metadata for hub.docker.local:5000/centos:latest:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to do request: Head "https://hub.docker.local:5000/v2/centos/manifests/latest": http: server gave HTTP response to HTTPS client
C:\mydocker-build>

As in the above command execution, it appears that the docker command execution ends in a failure.

Solution

So, the following is the attempt to solve the error message as in the description available in the introduction part. The sequence action exist as follows :

  1. First of all, try to ping the name of the URL private registry repository as follows :

    C:\mydocker-build>ping hub.docker.local
    Pinging hub.docker.local [127.0.0.1] with 32 bytes of data:
    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Ping statistics for 127.0.0.1: Packets: Sent = 2, Received = 2, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms Control-C ^C C:\mydocker-build>
    

    The ping process is a success where it can resolve the name of ‘hub.docker.local’. Actually, the definition of the ‘hub.docker.local’ exist in the name configuration file. That name configuration file exist in ‘C:\Windows\System32\drivers\etc\hosts’. The following is the line defining the ‘hub.docker.local’ name server :

    FROM 127.0.0.1:5000/centos
    # Copyright (c) 1993-2009 Microsoft Corp.
    #
    # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    #
    # This file contains the mappings of IP addresses to host names. Each
    # entry should be kept on an individual line. The IP address should
    # be placed in the first column followed by the corresponding host name.
    # The IP address and the host name should be separated by at least one
    # space.
    #
    # Additionally, comments (such as these) may be inserted on individual
    # lines or following the machine name denoted by a '#' symbol.
    #
    # For example:
    #
    # 102.54.94.97 rhino.acme.com # source server
    # 38.25.63.10 x.acme.com # x client host
    # localhost name resolution is handled within DNS itself.
    # 127.0.0.1 localhost
    # ::1 localhost
    
  2. So, the address of ‘hub.docker.local’ is available and it is possible for further resolve. But it does not working within the Dockerfile file. So, modify the Dockerfile file by changing the URL of the private registry repository as follows :

    127.0.0.1 hub.docker.local
  3. Finally, execute the previous command once more. The following is the output of the command execution :

    C:\mydocker-build>docker build --tag hello-world:latest .
    [+] Building 1.0s (5/5) FINISHED
    => [internal] load build definition from Dockerfile 0.7s
    => => transferring dockerfile: 388B 0.7s
    => [internal] load .dockerignore 0.1s
    => => transferring context: 2B 0.0s
    => [internal] load metadata for 127.0.0.1:5000/centos:latest 0.2s
    => CACHED [1/1] FROM 127.0.0.1:5000/centos@sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3aab063a7fdb9dc 0.0s
    => exporting to image 0.0s
    => => exporting layers 0.0s
    => => writing image sha256:22773018c04267669821153cd42ef21101902b10a8a16f340fbef85a77821d03 0.0s
    => => naming to docker.io/library/hello-world:latest 0.0s
    Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
    C:\mydocker-build>
    

    Fortunately, it is a success. So, basically in case of resolving a local private registry repository, if it fail in the resolve process, just use the IP address of it. In this case, it is ‘127.0.0.1’.

Leave a Reply