怎么配置才能够让 wsl2 中的 docker 容器访问本地代理?

2 天前
 asd999cxcx
我本地用 clash verge rev ,使用 wsl2 装了 debian ,同时装了 docker desktop for windows 并且整合到 wsl2 ,然后我使用 vscode 访问容器,发现使用插件初始化项目的时候提示初始化项目失败,然后我打开 vscode 的开发者工具就提示连接到 127.0.0.1:7897 失败,我尝试关闭本地 vpn 然后再用 vscode 访问容器就可以正常进行项目初始化操作了,请问我该怎么在本地开启 vpn 的情况下同时能正常进行项目创建操作?
609 次点击
所在节点    问与答
20 条回复
proxytoworld
1 天前
安装 vmware ,访问 vmware 网卡的 ip
asd999cxcx
1 天前
@proxytoworld 意思是换成 wmware 开发吗?
proxytoworld
1 天前
不是啊,wsl2 能够访问 vmware 的网卡,你把代理设置成 vmware 网卡就是固定 IP 了
zhtyytg
1 天前
wsl2 镜像不是能直接用本地主机代理?
hljhbing
1 天前
如果是 WSL 中的 docker ,可以命令行执行。
export http_proxy="http://127.0.0.1:7890"
export https_proxy="http://127.0.0.1:7890"
export ftp_proxy="http://127.0.0.1:7890"

clash 开启 allow lan ,上面修改地址到到你宿主机的 IP ,不要用 127.0.0.1 ,不通的,端口改到 clash port
proxytoworld
1 天前
@hljhbing wsl2 127 不是宿主机的...
Gitmeeri
1 天前
代理换成 tunnel 模式
asd999cxcx
1 天前
@zhtyytg WSL2 是这么配置的: https://imgur.com/a/0hokJxG ,然后我用 docker desktop 起了个 debian 的容器,用 vscode 连上去,初始化 spring 项目的时候弹框 提示: https://imgur.com/D9eywwY 开发人员工具提示: https://imgur.com/tFPn4qf
asd999cxcx
1 天前
@hljhbing 这个是在 wsl 中执行还是容器中执行?
asd999cxcx
1 天前
@Gitmeeri 我试了下用 tun 模式其他的没变,依旧是不行的
asd999cxcx
1 天前
@hljhbing
@proxytoworld 我在 wsl2 中看到的宿主机 ip 是:
nameserver 10.255.255.254
那我是吧 ip 改成这个就行了嘛?
proxytoworld
1 天前
我没话说
zhtyytg
1 天前
@asd999cxcx #8 少了一个配置项吧,要开启那个本地回环的参数 hostAddressLoopback
hljhbing
1 天前
@asd999cxcx #9 WSL 中,如果用 vscode 访问,就是 vscode 的命令行中 都试试
asd999cxcx
1 天前
@hljhbing 这个 ip 是改成对应的#11 中提到的 /etc/resolv.conf 中显示的 nameserver 的 ip 吗?
asd999cxcx
1 天前
@zhtyytg 刚刚加上了 hostAddressLoopback ,clash verge rev 里面的回环也都勾选了,重启了 wsl 之后还是和刚开始一样的提示
zhtyytg
15 小时 6 分钟前
@asd999cxcx #16 那我不知道了,建议你先进 wsl 里试一下代理是不是正常的(比如 curl ip.sb 看看 ip 源)。你这个报错可能不是 vpn 代理问题导致的
hljhbing
14 小时 19 分钟前
@asd999cxcx #15 nameserver 是 DNS 地址 显然不是,是 WSL 所在的宿主机的 IP ,内网的
asd999cxcx
9 小时 3 分钟前
@zhtyytg 我在 wsl 里面试了下代理是正常的,美国的节点
asd999cxcx
6 小时 27 分钟前
@hljhbing 执行出来是这样的:
root@mini-pc:~# hostname -I
198.10.0.1 100.94.203.16 192.168.0.105 fdfe:dcba:9876::1 fd7a:115c:a1e0::1e01:cb10
root@mini-pc:~# ip route
default dev eth0 proto kernel scope link
default via 192.168.0.1 dev eth3 proto kernel metric 25
100.72.164.16 dev eth1 proto kernel scope link metric 5
100.78.145.44 dev eth1 proto kernel scope link metric 5
100.96.113.45 dev eth1 proto kernel scope link metric 5
100.97.11.125 dev eth1 proto kernel scope link metric 5
100.100.100.100 dev eth1 proto kernel scope link metric 5
100.110.174.125 dev eth1 proto kernel scope link metric 5
100.113.68.36 dev eth1 proto kernel scope link metric 5
100.114.35.105 dev eth1 proto kernel scope link metric 5
192.168.0.0/24 dev eth3 proto kernel scope link metric 281
192.168.0.1 dev eth3 proto kernel scope link metric 25
198.10.0.0/30 dev eth0 proto kernel scope link metric 256

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1076603

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX