@@ -20,7 +20,6 @@ import (
2020 "fmt"
2121 "math/rand"
2222 "net/http"
23- "os"
2423 "path"
2524 "strconv"
2625 "strings"
@@ -283,19 +282,14 @@ func LogSymlink(containerLogsDir, podFullName, containerName, dockerId string) s
283282 return path .Join (containerLogsDir , fmt .Sprintf ("%s_%s-%s.%s" , podFullName , containerName , dockerId , LogSuffix ))
284283}
285284
286- // Get a docker endpoint , either from the string passed in, or $DOCKER_HOST environment variables
287- func getDockerEndpoint ( dockerEndpoint string ) string {
288- var endpoint string
285+ // Get a * docker.Client , either using the endpoint passed in, or using
286+ // DOCKER_HOST, DOCKER_TLS_VERIFY, and DOCKER_CERT path per their spec
287+ func getDockerClient ( dockerEndpoint string ) ( * docker. Client , error ) {
289288 if len (dockerEndpoint ) > 0 {
290- endpoint = dockerEndpoint
291- } else if len (os .Getenv ("DOCKER_HOST" )) > 0 {
292- endpoint = os .Getenv ("DOCKER_HOST" )
293- } else {
294- endpoint = "unix:///var/run/docker.sock"
289+ glog .Infof ("Connecting to docker on %s" , dockerEndpoint )
290+ return docker .NewClient (dockerEndpoint )
295291 }
296- glog .Infof ("Connecting to docker on %s" , endpoint )
297-
298- return endpoint
292+ return docker .NewClientFromEnv ()
299293}
300294
301295func ConnectToDockerOrDie (dockerEndpoint string ) DockerInterface {
@@ -304,7 +298,7 @@ func ConnectToDockerOrDie(dockerEndpoint string) DockerInterface {
304298 VersionInfo : docker.Env {"ApiVersion=1.18" },
305299 }
306300 }
307- client , err := docker . NewClient ( getDockerEndpoint ( dockerEndpoint ) )
301+ client , err := getDockerClient ( dockerEndpoint )
308302 if err != nil {
309303 glog .Fatalf ("Couldn't connect to docker: %v" , err )
310304 }
0 commit comments