-
-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support WSL 2 on Windows #1055
Comments
@tbtmuse yep we are aware and frankly can't wait already! If the performance is going to be good, this is going to be no less than an epic change.
|
We'll have to explore the best approach to supporting and using WSL 2. WSL 2 is not a revolutionary approach but rather an attempt to flip the issue (file system access and performance) on its head. It's pretty much the same as having a Linux environment in a VM that you connect to via SSH. Specifically:
|
Noting here that I was able to get this working by doing the following:
For Google Chrome / Selenium Driver Usage:
Example port and firewall rules script; run as administrator using Task Scheduler:
$remoteip = wsl.exe /bin/bash -c "ip addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'"
$found = $remoteip -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( !$found ){
echo "The Script Exited, the ip address of WSL 2 cannot be found";
exit;
}
#[Ports]
#All the ports you want to forward separated by comma
$ports=@(80,8080,443,10000,3000,5000);
#[Static ip]
#You can change the addr to your ip config to listen to a specific address
$addr='0.0.0.0';
$ports_a = $ports -join ",";
#Remove Firewall Exception Rules
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";
#adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -RemoteAddress $remoteip -Action Allow -Protocol TCP";
for( $i = 0; $i -lt $ports.length; $i++ ){
$port = $ports[$i];
iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteip";
} See below comment #1055 (comment) for benchmarks. |
@cybtachyon thanks for the report. The last step is probably not necessary since there is fin hosts command for that. |
Updated the steps - thanks! |
Difficult - likely not. Will it take time - certainly. Can you help by getting involved in a feature you are interested to see implemented - I'm glad you asked! Here's how:
|
when is the release date for WSL2? |
Just tested Docksal on WSL2 on the latest SLOW ring of insider preview build (19041.207). Works well and it works even with native linux Docker. Other words: Docker for Windows potentially is not needed anymore! WSL2 Installation
Drupal speedTestingI've just created a drupal project in the WSL user's home directory and ran .docksal/commands/test1#!/usr/bin/env bash
# Stop on error
set -e
i=1
max=5
while [ $i -le $max ]
do
echo "[$i/$max] Running site install..."
time (fin exec drush si standard --db-url=mysql://root:root@db/default --yes --quiet)
i=$(( $i + 1 ))
done For testing WSL2 I've created a project directory in WSL's user home directory: Results
WSL1:
WSL2:
File system speed testingI've just run .docksal/commands/test2#!/usr/bin/env bash
# Stop on error
set -e
i=1
max=5
while [ $i -le $max ]
do
echo "[$i/$max] Running test OUTside container ..."
dd if=/dev/zero of=./test bs=512M count=20 oflag=direct && rm ./test
i=$(( $i + 1 ))
done
echo "- - - - - - - - - - - - - - - - - - - - - - - -"
i=1
max=5
while [ $i -le $max ]
do
echo "[$i/$max] Running test INside container ..."
fin exec dd if=/dev/zero of=./test bs=512M count=20 oflag=direct && rm ./test
i=$(( $i + 1 ))
done
That's insane! 🤪 Also I found that WSL2/WSL1 can be detected by kernel version:
So it's possible to just grep |
@alexander-danilenko this is great analysis. Looking forward to trying out WSL2 for myself. |
WSL2 is available on many Windows 10 systems now with the 2004 update (slow rollout). I have gone over my instructions in #1055 (comment) , and added support for XDEBUG and other Inbound connection tooling.
There's a couple things I don't understand which makes it difficult for me to contribute a PR, such as how DOCKSAL_HOST_IP is determined on Windows, or the best way to add firewall rules on Windows for Docksal/WSL2 (especially since the IP changes every time). I'd appreciate any insight, or at least enough that we could hack together a PR for this issue. |
@cybtachyon , on line 5 of your powershell command, shouldn't (Also, hello, Bloom from the Particle project here! It's awesome knowing you're rocking WSL2!!) |
Heya! Good catch, that's a leftover variable from the first iteration of the script. The matching is more robust now. I removed it as it's not needed anymore. Thanks! |
Noting here that on a pre-release version of Windows (Build 20180.1000), local IP's 0.0.0.0 and 127.0.0.1 were disabled by default while I needed to run |
I can verify the above works after a system restart. Because Windows. |
Also throwing this out there: Make sure to restart your |
Is this working out of the box at this point? I'd love to be able to switch to WSL2 since I've had some weird intermittent issues with SMB shares. I noticed the install docs for Windows don't specify WSL1 or 2, and the Microsoft page about it recommends WSL2, so it is de facto the default for new users at this point... |
@ethanbb We would need a PR that adds automation to the steps listed above. One issue is there is not an easy way to add the needed firewall exceptions via docksal. I would consider that a blocking bug in WSL2, unless we find a way to script it in bash. See #1055 (comment) for the most up-to-date steps required. |
Any official update on this being fully supported? I'm getting a new machine soon and would love to go with WSL2 for the speed boost. |
Work on WSL2 support in Docksal is underway. |
Also want to confirm that the solution above works and the speed gain is amazing. My main reason for looking into WSL2 is because I was testing out Wingsuit DS for Drupal. With WSL, Webpack (using watch) was taking about 2 minutes to recompile after a file changes. After switching to WSL2, it takes less than a second! Looking forward to this integration in future release of Docksal. |
@lmakarov Is there a branch up or a doc tracking what's being done / needs to be done? I'd like to contribute. Here's what I'm aware of as tasks:
|
Hi, So it seems that the only think missing here is a dns entry (or a hosts modification) |
ok, I finally get working Docksal with wsl2 :
edit hosts file : [EDIT] |
@obriat you are a GOD. This worked perfectly. Wow. |
OK but my solution doesn't benefit from the *.docksal.site wildcard DNS, another solution is to fix your HyperV interface IP. Open Powsershell with admin rights and type: Edit this command if your HyperV interface has another name ( I also open a discusion about this point here: #1565 |
I use Docksal on WSL2, it works good, but Xdebug doesn't stop on the breakpoints. PHPStorm even doesn't react on requests. Is there any specific instructions to make Xdebug work in WSL2? |
Yes, see above.
|
In my case this didn't help me. I solved my problem by assigning IP of host.docker.internal to client_host and remote_host |
I've had no luck with PHPStorm, but @cybtachyon's instructions oddly seem to work fine when using VSCode. After doing some digging, it looks like the Windows IP Helper service is blocking port 9000, which is preventing PHPStorm from listening on that port. I'd be curious to know if anyone else has experienced this same issue. |
Unrelated to any issue with PHPStorm, but if you use VSCode with the Remote - WSL extension, i.e. Code is running on the Linux VM, you don't need to change DOCKSAL_HOST_IP. Maybe obvious but I was uncertain when XDebug wasn't working. (My actual issue was not setting XDEBUG_ENABLED="1" 🤦♂️) |
I'm using PHPStorm and Xdebug works fine with it. In addition to following instructions from cybtachyon #1055 (comment) I did this:
Also have this in my docksal.env under [project_root]/.docksal directory |
I don't see any difference in what you're describing and what I've configured for my project. I still can't get PHPStorm to debug anything. On further inspection, I notice that the Windows IP Helper service seems to be using port 9000 for some reason. When triggering PHPStorm to listen for XDebug on port 9000, I get a notification from PHPStorm saying "Port 9000 is busy". However, when I go to Settings and validate debugger configuration (under PHP > Debug), I get a successful result. So my next thought was, ok, port 9000 is busy so let me just configure XDebug to use port 9001 instead. Should be easy enough, and it was. I created
I run Except PHPStorm still doesn't pick up the connection when using my browser. I'm beginning to think JetBrains might just be releasing updates that are breaking WSL2 features. |
Works for me. Running Build #PS-213.5744.279, built on December 2, 2021 of
PHPStorm. Windows 11.
…On Fri, Jan 14, 2022 at 1:30 PM Erik ***@***.***> wrote:
I'm using PHPStorm and Xdebug works fine with it. In addition to following
instructions from cybtachyon #1055 (comment)
<#1055 (comment)> I
did this:
I don't see any difference in what you're describing and what I've
configured for my project. I still can't get PHPStorm to debug anything. On
further inspection, I notice that the Windows IP Helper service seems to be
using port 9000 for some reason. When triggering PHPStorm to listen for
XDebug on port 9000, I get a notification from PHPStorm saying "Port 9000
is busy".
However, when I go to Settings and validate debugger configuration (under
PHP > Debug), I get a successful result.
So my next thought was, ok, port 9000 is busy so let me just configure
XDebug to use port 9001 instead. Should be easy enough, and it was. I
created docksal-local.yml and added this:
version: '2.1'
services:
cli:
expose:
- 9001
environment:
- XDEBUG_CONFIG=client_host=${DOCKSAL_HOST_IP} client_port=9001 remote_host=${DOCKSAL_HOST_IP} remote_port=9001
I run fin restart, go back to Settings in PHPStorm, change the port to
9001 and validate XDebug configuration again. Again validation succeeds,
this time confirming report port 9001. I'm able to toggle on listening for
PHP XDebug connections. No notifications. If I check Windows, I can see
that PHPStorm is using port 9001. All looks good.
Except PHPStorm still doesn't pick up the connection when using my browser.
I'm beginning to think JetBrains might just be releasing updates that are
breaking WSL2 features.
—
Reply to this email directly, view it on GitHub
<#1055 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEZWYTEVBWLZ3RPFNJNOOV3UWBTTRANCNFSM4HLFTHMA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you commented.Message ID:
***@***.***>
--
Dmytro Boichev
***@***.***
|
I discovered my issue. It was actually very simple, but I'll mention it here in case someone else runs across this. I was grabbing the Powershell script posted above and running it to open ports between Windows and WSL2. At some point I had port 9000 in my list of ports to open. I had removed that port from the script later. But of course (and as a I developer I should have recognized this much sooner than I did), that does not remove the firewall rule that was established the last time I ran it. So from that point forward, port 9000 was open and being manged by the IP Helper service in Windows 10. So just keep in mind that you'll need to specifically remove the firewall rules for the port you no longer want to proxy between Windows and WLS2. Or make a new script for removing ports. |
I just discovered that all the WSL mentions in |
I'm staring a PR in order to remove WSL1 support. The remaining tasks:
|
Love your project, just wanted to put this here, so you can keep an eye on it, and possibly prepare for it since it's around the corner.
https://devblogs.microsoft.com/commandline/announcing-wsl-2/
The text was updated successfully, but these errors were encountered: