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