浏览代码

Merge pull request #3303 from crosbymichael/add-host-flag

Add DOCKER_HOST env var for client
Andy Rothfusz 11 年之前
父节点
当前提交
1bc3f6b7b5
共有 2 个文件被更改,包括 19 次插入2 次删除
  1. 7 2
      docker/docker.go
  2. 12 0
      docs/sources/commandline/cli.rst

+ 7 - 2
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 != "" {

+ 12 - 0
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``