V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
asd999cxcx
V2EX  ›  问与答

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

  •  
  •   asd999cxcx · 2 天前 · 610 次点击
    我本地用 clash verge rev ,使用 wsl2 装了 debian ,同时装了 docker desktop for windows 并且整合到 wsl2 ,然后我使用 vscode 访问容器,发现使用插件初始化项目的时候提示初始化项目失败,然后我打开 vscode 的开发者工具就提示连接到 127.0.0.1:7897 失败,我尝试关闭本地 vpn 然后再用 vscode 访问容器就可以正常进行项目初始化操作了,请问我该怎么在本地开启 vpn 的情况下同时能正常进行项目创建操作?
    20 条回复    2024-09-30 17:05:00 +08:00
    proxytoworld
        1
    proxytoworld  
       1 天前
    安装 vmware ,访问 vmware 网卡的 ip
    asd999cxcx
        2
    asd999cxcx  
    OP
       1 天前
    @proxytoworld 意思是换成 wmware 开发吗?
    proxytoworld
        3
    proxytoworld  
       1 天前
    不是啊,wsl2 能够访问 vmware 的网卡,你把代理设置成 vmware 网卡就是固定 IP 了
    zhtyytg
        4
    zhtyytg  
       1 天前
    wsl2 镜像不是能直接用本地主机代理?
    hljhbing
        5
    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
        6
    proxytoworld  
       1 天前
    @hljhbing wsl2 127 不是宿主机的...
    Gitmeeri
        7
    Gitmeeri  
       1 天前 via Android   ❤️ 1
    代理换成 tunnel 模式
    asd999cxcx
        8
    asd999cxcx  
    OP
       1 天前
    @zhtyytg WSL2 是这么配置的: https://imgur.com/a/0hokJxG ,然后我用 docker desktop 起了个 debian 的容器,用 vscode 连上去,初始化 spring 项目的时候弹框 提示: https://imgur.com/D9eywwY 开发人员工具提示: https://imgur.com/tFPn4qf
    asd999cxcx
        9
    asd999cxcx  
    OP
       1 天前
    @hljhbing 这个是在 wsl 中执行还是容器中执行?
    asd999cxcx
        10
    asd999cxcx  
    OP
       1 天前
    @Gitmeeri 我试了下用 tun 模式其他的没变,依旧是不行的
    asd999cxcx
        11
    asd999cxcx  
    OP
       1 天前
    @hljhbing
    @proxytoworld 我在 wsl2 中看到的宿主机 ip 是:
    nameserver 10.255.255.254
    那我是吧 ip 改成这个就行了嘛?
    proxytoworld
        12
    proxytoworld  
       1 天前
    我没话说
    zhtyytg
        13
    zhtyytg  
       1 天前
    @asd999cxcx #8 少了一个配置项吧,要开启那个本地回环的参数 hostAddressLoopback
    hljhbing
        14
    hljhbing  
       1 天前
    @asd999cxcx #9 WSL 中,如果用 vscode 访问,就是 vscode 的命令行中 都试试
    asd999cxcx
        15
    asd999cxcx  
    OP
       1 天前
    @hljhbing 这个 ip 是改成对应的#11 中提到的 /etc/resolv.conf 中显示的 nameserver 的 ip 吗?
    asd999cxcx
        16
    asd999cxcx  
    OP
       1 天前
    @zhtyytg 刚刚加上了 hostAddressLoopback ,clash verge rev 里面的回环也都勾选了,重启了 wsl 之后还是和刚开始一样的提示
    zhtyytg
        17
    zhtyytg  
       15 小时 6 分钟前
    @asd999cxcx #16 那我不知道了,建议你先进 wsl 里试一下代理是不是正常的(比如 curl ip.sb 看看 ip 源)。你这个报错可能不是 vpn 代理问题导致的
    hljhbing
        18
    hljhbing  
       14 小时 19 分钟前
    @asd999cxcx #15 nameserver 是 DNS 地址 显然不是,是 WSL 所在的宿主机的 IP ,内网的
    asd999cxcx
        19
    asd999cxcx  
    OP
       9 小时 3 分钟前
    @zhtyytg 我在 wsl 里面试了下代理是正常的,美国的节点
    asd999cxcx
        20
    asd999cxcx  
    OP
       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
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2109 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:32 · PVG 23:32 · LAX 08:32 · JFK 11:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.