安装Docker时,WSL2 lan重定向问题。

问题描述 投票:0回答:1

我目前的设置是我的笔记本电脑和台式机,它们连接在同一个网络中。我是做webdev的,所以我在笔记本上写代码,在桌面的浏览器上看到结果。安装了docker之后,我不能再直接访问我的笔记本上在WSL2里面运行的web服务器,只能在Docker容器里面运行。

这个问题在WSL1中是不存在的,这是。

如果你在你的windows机器上安装docker桌面,并启用新的WSL2集成,它将会扰乱你的windows "hosts "文件(可以在 %SYSTEMROOT%\System32\drivers\etc\hosts)

Docker会自动添加以下内容。

# Added by Docker Desktop
192.168.1.77 host.docker.internal
192.168.1.77 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal

请注意,192.168.1.77是我的笔记本静态IP,我在路由器上设置的

我的猜测是,这些输入是重定向我的桌面的请求到docker,完全打破了直接访问.这是不理想的,因为我必须建立一个容器编码一个简单的反应应用程序,这导致了很多无用的复杂性。

ps: 我试过在hosts文件中输入以下内容,没有成功。

192.168.1.77 localhost

也没有成功

172.22.3.92 ubuntu.wsl    # managed by wsl2-host (service that creates a hostname for WSL2 ip)

192.168.1.77 ubuntu.wsl

唯一的解决方法是禁用docker和清理hosts文件,但这并不是它真正应该做的。

docker redirect windows-subsystem-for-linux lan
1个回答
0
投票

将此添加到~.wslconfig(win)或etcwsl.conf(wsl)中。

[network]
generateHosts = false
© www.soinside.com 2019 - 2024. All rights reserved.