diff --git a/cli.go b/cli.go index d1e88c9..aab4dc9 100644 --- a/cli.go +++ b/cli.go @@ -11,6 +11,7 @@ type GlobalOptions struct { TLSCert string `long:"tlscert" value-name:"~/.docker/cert.pem" description:"Path to TLS certificate file"` TLSKey string `long:"tlskey" value-name:"~/.docker/key.pem" description:"Path to TLS key file"` TLSVerify bool `long:"tlsverify" description:"Use TLS and verify the remote"` + Host string `long:"host" short:"H" value-name:"unix:///var/run/docker.sock" description:"Docker host to connect to"` } var globalOptions GlobalOptions diff --git a/containers.go b/containers.go index e537b48..2029a42 100644 --- a/containers.go +++ b/containers.go @@ -51,6 +51,9 @@ func (x *ContainersCommand) Execute(args []string) error { } else { client, err := connect() + if err != nil { + return err + } clientContainers, err := client.ListContainers(docker.ListContainersOptions{All: true}) if err != nil { diff --git a/util.go b/util.go index 2f7571e..728baea 100644 --- a/util.go +++ b/util.go @@ -11,8 +11,13 @@ import ( func connect() (*docker.Client, error) { // grab directly from docker daemon - endpoint := os.Getenv("DOCKER_HOST") - if len(endpoint) == 0 { + var endpoint string + if env_endpoint := os.Getenv("DOCKER_HOST"); len(env_endpoint) > 0 { + endpoint = env_endpoint + } else if len(globalOptions.Host) > 0 { + endpoint = globalOptions.Host + } else { + // assume local socket endpoint = "unix:///var/run/docker.sock" }