WSL: WSL mirrored network Docker container cannot access Windows service
Windows Version
Microsoft Windows [版本 10.0.22631.2861]
WSL Version
2.0.14.0
Are you using WSL 1 or WSL 2?
- WSL 2
- WSL 1
Kernel Version
Linux version 5.15.133.1-microsoft-standard-WSL2
Distro Version
Arch Linux
Other Software
No response
Repro Steps
1.Instead of using docker desktop, I used the docker ce
sudo pacman -Qs docker
local/docker 1:24.0.7-1
Pack, ship and run any application as a lightweight container
local/docker-buildx 0.12.0-1
Docker CLI plugin for extended build capabilities with BuildKit
local/docker-compose 2.23.3-1
Fast, isolated development environments using Docker
sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: disabled)
Drop-In: /etc/systemd/system/docker.service.d
└─proxy.conf
Active: active (running) since Sat 2023-12-16 13:46:04 CST; 9min ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 165 (dockerd)
Tasks: 21
Memory: 109.4M ()
CPU: 662ms
CGroup: /system.slice/docker.service
└─165 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
- windows network inteface info
以太网适配器 vEthernet (static):
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::51c4:d9e0:abc3:cec4%6
IPv4 地址 . . . . . . . . . . . . : 192.168.10.1
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . :
无线局域网适配器 本地连接* 1:
媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
无线局域网适配器 本地连接* 2:
媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
无线局域网适配器 WLAN:
连接特定的 DNS 后缀 . . . . . . . : lan
本地链接 IPv6 地址. . . . . . . . : fe80::69e5:7c68:6893:d9cd%27
IPv4 地址 . . . . . . . . . . . . : 192.168.123.68
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . : 192.168.123.1
以太网适配器 vEthernet (Default Switch):
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::39f:faf5:890b:9706%48
IPv4 地址 . . . . . . . . . . . . : 172.23.64.1
子网掩码 . . . . . . . . . . . . : 255.255.240.0
默认网关. . . . . . . . . . . . . :
以太网适配器 vEthernet (WSL (Hyper-V firewall)):
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::1d6b:1d8:63c6:325a%67
IPv4 地址 . . . . . . . . . . . . : 172.29.96.1
子网掩码 . . . . . . . . . . . . : 255.255.240.0
默认网关. . . . . . . . . . . . . :
以太网适配器 vEthernet (BluestacksNxt):
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::b997:930:b729:56ed%71
IPv4 地址 . . . . . . . . . . . . : 172.23.32.1
子网掩码 . . . . . . . . . . . . : 255.255.240.0
默认网关. . . . . . . . . . . . . :
以太网适配器 vEthernet (WSL):
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::6275:cd47:bd0b:d612%77
IPv4 地址 . . . . . . . . . . . . : 172.26.0.1
子网掩码 . . . . . . . . . . . . : 255.255.240.0
默认网关. . . . . . . . . . . . . :
- wslconfig
[wsl2]
memory=16GB
swap=8GB
guiApplications=true
networkingMode=mirrored
dnsTunneling=true
firewall=false
autoProxy=true
hostAddressLoopback=true
[experimental]
autoMemoryReclaim=gradual
sparseVhd=true
- wsl network mode
wslinfo --networking-mode
mirrored
if network mode is nat, I can use default switch gateway ip to access windows services.
- I have a proxy service running in windows
➜ netstat -ano | findstr "7890"
TCP 0.0.0.0:7890 0.0.0.0:0 LISTENING 30596
TCP [::]:7890 [::]:0 LISTENING 30596
UDP 0.0.0.0:7890 *:* 30596
UDP [::]:7890 *:* 30596
- When I was running the docker container in wsl, the connection failed when I accessed the 7890 port on the windows 192.168.123.68 or 192.168.10.1 LAN IP
- windows
➜ curl -I -svo /dev/null -x http://192.168.123.68:7890 https://www.google.com
* Trying 192.168.123.68:7890...
* Connected to 192.168.123.68 (192.168.123.68) port 7890
* CONNECT tunnel: HTTP/1.1 negotiated
* allocate connect buffer
* Establish HTTP proxy tunnel to www.google.com:443
> CONNECT www.google.com:443 HTTP/1.1
> Host: www.google.com:443
> User-Agent: curl/8.4.0
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection established
* Closing connection
- docker in wsl
~❯ docker run -it --rm debian:11 curl -I -svo /dev/null -x http://192.168.123.68:7890 https://www.google.com
* Trying 192.168.10.1:7890...
* connect to 192.168.10.1 port 7890 failed: Connection refused
* Failed to connect to 192.168.10.1 port 7890: Connection refused
* Closing connection 0
- I’ve tried turning off the windows and hyper-v firewall but it doesn’t work。 Run container with host network , it can access the windows proxy service. I have also tried the nginx service running on windows , the container also cannot access the service.
Is there a solution for containers to access windows services even in bridge mode?
Expected Behavior
~❯ docker run -it --rm debian:11 curl -I -svo /dev/null -x http://192.168.123.68:7890 https://www.google.com
* Trying 192.168.123.68:7890...
* Connected to 192.168.123.68 (192.168.123.68) port 7890
* CONNECT tunnel: HTTP/1.1 negotiated
* allocate connect buffer
* Establish HTTP proxy tunnel to www.google.com:443
> CONNECT www.google.com:443 HTTP/1.1
> Host: www.google.com:443
> User-Agent: curl/8.4.0
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection established
* Closing connection
Actual Behavior
~❯ docker run -it --rm debian:11 curl -I -svo /dev/null -x http://192.168.123.68:7890 https://www.google.com
* Trying 192.168.10.1:7890...
* connect to 192.168.10.1 port 7890 failed: Connection refused
* Failed to connect to 192.168.10.1 port 7890: Connection refused
* Closing connection 0
Diagnostic Logs
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 22 (1 by maintainers)
@nicolus This is already fixed for me. My WSL Info and Docker-CE Version
Access nginx service In Windows from wsl docker container (Container use default bridge network)
Fixed with https://github.com/microsoft/WSL/releases/tag/2.3.11.