Merge pull request #12471 from peter-edge/docker-new-client-from-env

Use docker.NewClientFromEnv for creation of docker.Client
This commit is contained in:
Alex Robinson 2015-08-10 14:22:21 -07:00
commit 20c189d752

View File

@ -20,7 +20,6 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"net/http" "net/http"
"os"
"path" "path"
"strconv" "strconv"
"strings" "strings"
@ -283,19 +282,14 @@ func LogSymlink(containerLogsDir, podFullName, containerName, dockerId string) s
return path.Join(containerLogsDir, fmt.Sprintf("%s_%s-%s.%s", podFullName, containerName, dockerId, LogSuffix)) return path.Join(containerLogsDir, fmt.Sprintf("%s_%s-%s.%s", podFullName, containerName, dockerId, LogSuffix))
} }
// Get a docker endpoint, either from the string passed in, or $DOCKER_HOST environment variables // Get a *docker.Client, either using the endpoint passed in, or using
func getDockerEndpoint(dockerEndpoint string) string { // DOCKER_HOST, DOCKER_TLS_VERIFY, and DOCKER_CERT path per their spec
var endpoint string func getDockerClient(dockerEndpoint string) (*docker.Client, error) {
if len(dockerEndpoint) > 0 { if len(dockerEndpoint) > 0 {
endpoint = dockerEndpoint glog.Infof("Connecting to docker on %s", dockerEndpoint)
} else if len(os.Getenv("DOCKER_HOST")) > 0 { return docker.NewClient(dockerEndpoint)
endpoint = os.Getenv("DOCKER_HOST")
} else {
endpoint = "unix:///var/run/docker.sock"
} }
glog.Infof("Connecting to docker on %s", endpoint) return docker.NewClientFromEnv()
return endpoint
} }
func ConnectToDockerOrDie(dockerEndpoint string) DockerInterface { func ConnectToDockerOrDie(dockerEndpoint string) DockerInterface {
@ -304,7 +298,7 @@ func ConnectToDockerOrDie(dockerEndpoint string) DockerInterface {
VersionInfo: docker.Env{"ApiVersion=1.18"}, VersionInfo: docker.Env{"ApiVersion=1.18"},
} }
} }
client, err := docker.NewClient(getDockerEndpoint(dockerEndpoint)) client, err := getDockerClient(dockerEndpoint)
if err != nil { if err != nil {
glog.Fatalf("Couldn't connect to docker: %v", err) glog.Fatalf("Couldn't connect to docker: %v", err)
} }