Mac docker内请求http(s)失败的问题处理

新建了一个docker容器,发现在容器内运行go get命令时会报错:

1
2
3
4
5
6
7
[root@27a3532133fa bin]# go get -u -v github.com/nsf/gocode
github.com/nsf/gocode (download)
# cd /home/work/data/www/go/src/github.com/nsf/gocode; git pull --ff-only
error: Failed connect to github.com:8888; Operation now in progress while accessing https://github.com/nsf/gocode/info/refs

fatal: HTTP request failed
package github.com/nsf/gocode: exit status 1

访问github.com时莫名其妙的多了一个8888端口,查了相关资料发现是Mac新版的docker加了个http_proxy代理:

1
2
[root@27a3532133fa bin]# echo $http_proxy
docker.for.mac.localhost:8888

找了很长时间也没发现怎么去掉这个http_proxy,最后发现可以将http_proxy这个环境变量定义为空,就可以把原来那个值覆盖掉,于是在~/.bash_profile加上

1
export http_proxy=""

再source ~/.bash_profile就可以了。