From 8c98858fcbdfcfd0ea1a3944605612408da3fcaa Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Thu, 30 Apr 2015 21:17:26 -0700 Subject: [PATCH] support boot2docker via environment variables --- images.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/images.go b/images.go index 53235e8..ad01cb9 100644 --- a/images.go +++ b/images.go @@ -8,6 +8,7 @@ import ( "fmt" "io/ioutil" "os" + "path" "strings" ) @@ -53,9 +54,25 @@ func (x *ImagesCommand) Execute(args []string) error { } else { // grab directly from docker daemon - client, err := docker.NewClient("unix:///var/run/docker.sock") - if err != nil { - return err + endpoint := os.Getenv("DOCKER_HOST") + if len(endpoint) == 0 { + endpoint = "unix:///var/run/docker.sock" + } + + var client *docker.Client + if dockerCertPath := os.Getenv("DOCKER_CERT_PATH"); len(dockerCertPath) > 0 { + cert := path.Join(dockerCertPath, "cert.pem") + key := path.Join(dockerCertPath, "key.pem") + ca := path.Join(dockerCertPath, "ca.pem") + client, err = docker.NewTLSClient(endpoint, cert, key, ca) + if err != nil { + return err + } + } else { + client, err = docker.NewClient(endpoint) + if err != nil { + return err + } } clientImages, err := client.ListImages(docker.ListImagesOptions{All: true})