简体   繁体   English

安装 Docker 时出现 WSL2 局域网重定向问题

[英]WSL2 lan redirection issue when Docker installed

My current setup is my laptop and desktop, they're connected in the same network.我当前的设置是我的笔记本电脑和台式机,它们连接在同一个网络中。 I do webdev so i code in my laptop and see the results in my desktop's browser.我做 webdev,所以我在我的笔记本电脑上编码,并在我的桌面浏览器中查看结果。 After installing docker i can no longer access my laptop's web servers that are being runned inside WSL2 directly, ONLY if they're running inside a Docker container.安装 docker 后,我无法再访问我的笔记本电脑的 web 服务器,这些服务器直接在 WSL2 中运行,前提是它们在 Docker 容器中运行。

This issue wasn't present in WSL1, which is: WSL1 中不存在此问题,即:

If you install docker desktop on your windows machine and enable the new WSL2 integration it will mess your windows 'hosts' file (found at %SYSTEMROOT%\System32\drivers\etc\hosts )如果您在 windows 机器上安装 docker 桌面并启用新的 WSL2 集成,它将弄乱您的 windows 'hosts' 文件(位于 System3 %SYSTEMROOT%\System32\drivers\etc\hosts

Docker automatically adds the following: 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

Note that 192.168.1.77 is my laptop static IP which i set in my router请注意,192.168.1.77 是我在路由器中设置的笔记本电脑 static IP

My guess is that these inputs are redirecting my desktop's requests to docker, completely breaking directly access.我的猜测是这些输入将我的桌面请求重定向到 docker,完全破坏了直接访问。 This is not ideal because i have to build a container for coding a simple react app which leads to alot of useless complexity这并不理想,因为我必须构建一个容器来编写一个简单的反应应用程序,这会导致很多无用的复杂性

ps: I have tried the following entries in hosts file, no success: ps:我在hosts文件中尝试了以下条目,没有成功:

192.168.1.77 localhost

also:还:

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

192.168.1.77 ubuntu.wsl

The only workaround is to disable docker and clean hosts file, which isn't really what it suposed to be.唯一的解决方法是禁用 docker 并清理主机文件,这并不是它应该的样子。

Add this to ~/.wslconfig (win) or /etc/wsl.conf (wsl)将此添加到 ~/.wslconfig (win) 或 /etc/wsl.conf (wsl)

[network]
generateHosts = false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WSL2 Docker Linux 卷的权限问题 - WSL2 Docker Linux Permission Issue with Volumes 尝试在 WSL2 上安装 docker 时出现问题 - Issue trying to install docker on WSL2 docker compose 安装在 wsl2 中的 ubuntu 中,未使用 cisco vpn 连接到互联网 - docker compose installed in ubuntu in wsl2 not connecting to internet with cisco vpn WSL2 上的 Docker 卷 - Docker Volumes on WSL2 如何在 WSL2 上公开 Docker TCP 套接字? (WSL 安装 Docker,不是 Docker 桌面) - How to expose Docker TCP socket on WSL2? (WSL-installed Docker, not Docker Desktop) 如何使 Docker 中的 Docker Swarm 可以被 LAN 上的另一台设备连接到 Windows(WSL2)? - How do you make Docker Swarm in Docker for Windows (WSL2) joinable by another device on the LAN? 在 WSL2 Ubuntu 18 LTS 上运行 docker 时出现问题 - Issue in running docker on WSL2 Ubuntu 18 LTS WSL2 - Docker Compose 卷安装权限问题 - WSL2 - Docker Compose volume mounting permission issue 使用 Docker Desktop 和 WSL2 时,我的卷安装在哪里? - Where are my volumes mounted when using Docker Desktop and WSL2? 使用 WSL2 时如何为 docker for windows 运行 iptables 命令 - How to run an iptables command for docker for windows when using WSL2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM