Skip to content
This repository was archived by the owner on Feb 27, 2018. It is now read-only.

Commit 792d7eb

Browse files
committed
add boot2docker ip to NO_PROXY list
The docker client respects the HTTP_PROXY environment variable for api calls since version 1.5. This kind of breaks the boot2docker scenario because docker is running on a local VM which most most certainly won't be reachable by the proxy. This commit changes `boot2docker shellinit` to append the DOCKER_HOST to the NO_PROXY variable.
1 parent 0a3a250 commit 792d7eb

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

cmds.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,34 @@ func exports(socket, certPath string) map[string]string {
228228
out["DOCKER_TLS_VERIFY"] = "1"
229229
}
230230

231+
//if a http_proxy is set, we need to make sure the boot2docker ip
232+
//is added to the NO_PROXY environment variable
233+
if os.Getenv("http_proxy") != "" || os.Getenv("HTTP_PROXY") != "" {
234+
//get the ip from the docket/DOCKER_HOST
235+
re := regexp.MustCompile("tcp://([^:]+):")
236+
if matches := re.FindStringSubmatch(socket); len(matches) == 2 {
237+
ip := matches[1]
238+
239+
//first check for an existing lower case no_proxy var
240+
no_proxy_var := "no_proxy"
241+
no_proxy_value := os.Getenv("no_proxy")
242+
//otherweise try allcaps HTTP_PROXY
243+
if no_proxy_value == "" {
244+
no_proxy_var = "NO_PROXY"
245+
no_proxy_value = os.Getenv("NO_PROXY")
246+
}
247+
248+
switch {
249+
case no_proxy_value == "":
250+
out[no_proxy_var] = ip
251+
case strings.Contains(no_proxy_value, ip):
252+
out[no_proxy_var] = no_proxy_value
253+
default:
254+
out[no_proxy_var] = fmt.Sprintf("%s,%s", no_proxy_value, ip)
255+
}
256+
}
257+
}
258+
231259
return out
232260
}
233261

0 commit comments

Comments
 (0)