2

如何在容器内使用 Host 代理

 3 years ago
source link: https://arminli.com/use-proxy-in-docker/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Armin's Blog

如何在容器内使用 Host 代理

March 22, 2017

现在 Docker 的应用场景越来越多,在容器内 git clone 也是一个很头痛的问题,这篇文章给出了在容器内使用本机代理的方法。

设置本机 ss 监听端口为 0.0.0.0

我使用的 ShadowsocksX-NG,可以直接在偏好中修改。

9cd77f2egy1fdvlkbd25vj20ww0qmq6a.jpg

通过docker run --net=host启动容器,使容器与 host 共享网络。

配置 .gitconfig

这里需要填 host 的 内网 ip,可以通过 ifconfig | grep "inet " | grep -v 127.0.0.1 查询,Mac 直接打开网络偏好也能看到内网 ip。

[http]
        proxy = socks5://172.20.162.149:1080
[https]
        proxy = socks5://172.20.162.149:1080

接下来可以愉快地 git clone 啦!

至此,我们完成了在容器内使用 host 代理的配置,如果配置 proxychains4 等工具,也是一样的道理。


Profile picture

Written by Armin Li , a venture capitalist. [Weibo] [Subscribe]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK