support specifying docker host endpoint
This commit is contained in:
parent
8053390d93
commit
5fc5050be2
3 changed files with 11 additions and 2 deletions
1
cli.go
1
cli.go
|
@ -11,6 +11,7 @@ type GlobalOptions struct {
|
||||||
TLSCert string `long:"tlscert" value-name:"~/.docker/cert.pem" description:"Path to TLS certificate file"`
|
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"`
|
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"`
|
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
|
var globalOptions GlobalOptions
|
||||||
|
|
|
@ -51,6 +51,9 @@ func (x *ContainersCommand) Execute(args []string) error {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
client, err := connect()
|
client, err := connect()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
clientContainers, err := client.ListContainers(docker.ListContainersOptions{All: true})
|
clientContainers, err := client.ListContainers(docker.ListContainersOptions{All: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
9
util.go
9
util.go
|
@ -11,8 +11,13 @@ import (
|
||||||
func connect() (*docker.Client, error) {
|
func connect() (*docker.Client, error) {
|
||||||
|
|
||||||
// grab directly from docker daemon
|
// grab directly from docker daemon
|
||||||
endpoint := os.Getenv("DOCKER_HOST")
|
var endpoint string
|
||||||
if len(endpoint) == 0 {
|
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"
|
endpoint = "unix:///var/run/docker.sock"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue