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

Commit 2e5c07c

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 ccd9032 commit 2e5c07c

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
@@ -224,6 +224,34 @@ func exports(socket, certPath string) map[string]string {
224224
out["DOCKER_TLS_VERIFY"] = "1"
225225
}
226226

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

0 commit comments

Comments
 (0)