66 "encoding/pem"
77 "net"
88 "net/http"
9+ "strings"
910 "time"
1011
1112 "github.com/docker/cli/cli/connhelper"
@@ -90,14 +91,19 @@ func (ep *Endpoint) ClientOpts() ([]client.Opt, error) {
9091 return nil , err
9192 }
9293 if helper == nil {
93- tlsConfig , err := ep .tlsConfig ()
94- if err != nil {
95- return nil , err
94+ // Check if we're connecting over a socket, because there's no
95+ // need to configure TLS for a socket connection.
96+ //
97+ // TODO(thaJeztah); make resolveDockerEndpoint and resolveDefaultDockerEndpoint not load TLS data,
98+ // and load TLS files lazily; see https://github.com/docker/cli/pull/1581
99+ if ! isSocket (ep .Host ) {
100+ tlsConfig , err := ep .tlsConfig ()
101+ if err != nil {
102+ return nil , err
103+ }
104+ result = append (result , withHTTPClient (tlsConfig ))
96105 }
97- result = append (result ,
98- withHTTPClient (tlsConfig ),
99- client .WithHost (ep .Host ),
100- )
106+ result = append (result , client .WithHost (ep .Host ))
101107 } else {
102108 result = append (result ,
103109 client .WithHTTPClient (& http.Client {
@@ -116,6 +122,17 @@ func (ep *Endpoint) ClientOpts() ([]client.Opt, error) {
116122 return result , nil
117123}
118124
125+ // isSocket checks if the given address is a Unix-socket (linux),
126+ // named pipe (Windows), or file-descriptor.
127+ func isSocket (addr string ) bool {
128+ switch proto , _ , _ := strings .Cut (addr , "://" ); proto {
129+ case "unix" , "npipe" , "fd" :
130+ return true
131+ default :
132+ return false
133+ }
134+ }
135+
119136func withHTTPClient (tlsConfig * tls.Config ) func (* client.Client ) error {
120137 return func (c * client.Client ) error {
121138 if tlsConfig == nil {
0 commit comments