Created
June 12, 2022 15:14
-
-
Save guitarrapc/9cafe020426f7d0651042cfbbed15af6 to your computer and use it in GitHub Desktop.
Allow WSL2 Ubuntu 22.04 to access Host Windows Docker Desktop (Windows 11 21H2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set this on Windows TaskScheduler with `At Logon, Run with highest priviledge, Delay task for 1min` | |
wsl.exe -d Ubuntu-22.04 --exec cat /etc/resolv.conf | |
Set-NetFirewallProfile -DisabledInterfaceAliases "vEthernet (WSL)" -Name Public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run -it --rm -p 8080:80 nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl "http://$(ip route list default | awk '{print $3}'):8080/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary
WSL2 connection to the Host Windows is blocked via Windows Firewall.
This can be unlock by disabling Firewall profile for Interface
WSL2 (vEthernet (WSL)
on Public profile.Due to WSL2 interface created everytime logged in to Windows, this operation would better run by TaskScheduler so that script will run everytime logged on.
日本語
ホスト Windows への WSL2 からの接続は Windows Firewall によってブロックされます。
これは Windows Firewall の Public Profile における
WSL2 (vEthernet (WSL)
を無効にすることで回避することができます。ただWSL2 のインターフェースは Windows へのログオンのたびに再作成されるため、この処理は タスクスケジューラーなどに登録して自動的に実行するようにする必要があります。
Reference