Post

Mirroed网络模式下WSL内的Docker容器代理方案

Mirroed网络模式下WSL内的Docker容器代理方案

需求概述

环境WIN11,WSL 版本: 2.4.13.0,WSL网络模式:Mirroed

需要在WSL的Docker容器内访问Windows宿主机代理。

WSL设置

这一步在Windows上进行。打开WSL Setting,在网络中打开主机地址回环这个选项

Mirroed网络模式下WSL内的Docker容器代理方案-20250419.png

只有这样,才能在WSL的Docker容器内访问到我们主机的代理端口。

容器内代理设置

在设置代理前,大家要先看好Windows宿主机的IP,方法大家应该都会。我的ip就是192.168.6.115

我是放在.zshrc内的,大家可以参考一下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ip="192.168.6.115"

alias proxy="
    export http_proxy=socks5://$ip:7890;
    export https_proxy=socks5://$ip:7890;
    export all_proxy=socks5://$ip:7890;
    export HTTP_PROXY=socks5://$ip:7890;
    export HTTPS_PROXY=socks5://$ip:7890;
    export ALL_PROXY=socks5://$ip:7890;"
alias unproxy="
    unset http_proxy;
    unset https_proxy;
    unset all_proxy;
    unset HTTP_PROXY;
    unset HTTPS_PROXY;
    unset ALL_PROXY;"

proxy

没错,就这么简单,可以curl ipinfo.io来验证一下。

This post is licensed under CC BY 4.0 by the author.