@@ -32,7 +32,6 @@ import (
3232 "github.com/docker/docker/api/types/registry"
3333 "github.com/docker/docker/api/types/swarm"
3434 "github.com/docker/docker/client"
35- "github.com/docker/go-connections/tlsconfig"
3635 "github.com/pkg/errors"
3736 "github.com/spf13/cobra"
3837)
@@ -345,7 +344,10 @@ func resolveDockerEndpoint(s store.Reader, contextName string) (docker.Endpoint,
345344
346345// Resolve the Docker endpoint for the default context (based on config, env vars and CLI flags)
347346func resolveDefaultDockerEndpoint (opts * cliflags.ClientOptions ) (docker.Endpoint , error ) {
348- host , err := getServerHost (opts .Hosts , opts .TLSOptions )
347+ // defaultToTLS determines whether we should use a TLS host as default
348+ // if nothing was configured by the user.
349+ defaultToTLS := opts .TLSOptions != nil
350+ host , err := getServerHost (opts .Hosts , defaultToTLS )
349351 if err != nil {
350352 return docker.Endpoint {}, err
351353 }
@@ -548,18 +550,15 @@ func NewDockerCli(ops ...CLIOption) (*DockerCli, error) {
548550 return cli , nil
549551}
550552
551- func getServerHost (hosts []string , tlsOptions * tlsconfig.Options ) (string , error ) {
552- var host string
553+ func getServerHost (hosts []string , defaultToTLS bool ) (string , error ) {
553554 switch len (hosts ) {
554555 case 0 :
555- host = os .Getenv (client .EnvOverrideHost )
556+ return dopts . ParseHost ( defaultToTLS , os .Getenv (client .EnvOverrideHost ) )
556557 case 1 :
557- host = hosts [0 ]
558+ return dopts . ParseHost ( defaultToTLS , hosts [0 ])
558559 default :
559560 return "" , errors .New ("Specify only one -H" )
560561 }
561-
562- return dopts .ParseHost (tlsOptions != nil , host )
563562}
564563
565564// UserAgent returns the user agent string used for making API requests
0 commit comments