From f50b8b08b5742c8e55df2d610d428c39cf1f4947 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 20 Dec 2013 19:30:41 -0500 Subject: [PATCH] Add DOCKER_HOST env var for client This env var will set the -H flag on the docker client. --- docker/docker.go | 9 +++++++-- docs/sources/commandline/cli.rst | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docker/docker.go b/docker/docker.go index 1b5457984c..2d7e04ce92 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -52,8 +52,13 @@ func main() { return } if flHosts.Len() == 0 { - // If we do not have a host, default to unix socket - flHosts.Set(fmt.Sprintf("unix://%s", docker.DEFAULTUNIXSOCKET)) + defaultHost := os.Getenv("DOCKER_HOST") + + if defaultHost == "" || *flDaemon { + // If we do not have a host, default to unix socket + defaultHost = fmt.Sprintf("unix://%s", docker.DEFAULTUNIXSOCKET) + } + flHosts.Set(defaultHost) } if *bridgeName != "" && *bridgeIp != "" { diff --git a/docs/sources/commandline/cli.rst b/docs/sources/commandline/cli.rst index 2d4e37d885..511bd4970f 100644 --- a/docs/sources/commandline/cli.rst +++ b/docs/sources/commandline/cli.rst @@ -52,6 +52,18 @@ To set the dns server for all docker containers, use ``docker -d -dns 8.8.8.8`` To run the daemon with debug output, use ``docker -d -D`` +The docker client will also honor the ``DOCKER_HOST`` environment variable to set +the ``-H`` flag for the client. + +:: + + docker -H tcp://0.0.0.0:4243 ps + # or + export DOCKER_HOST="tcp://0.0.0.0:4243" + docker ps + # both are equal + + .. _cli_attach: ``attach``