Welcome to new things

[Technical] [Electronic work] [Gadget] [Game] memo writing

The story of how I moved to WSL2 because Puppeteer stopped working at WSL1.

I have been using WSL1 and was thinking of using WSL2 sometime in the future when it becomes more stable, but now I have moved to WSL2 out of necessity.

I'm going to write about the transition from WSL1 to WSL2 and the related Docker and X Server settings in a rambling manner.

The impetus for the transition

I was running puppeteer on WSL1+VcXsrv (X Server) and it stopped working with Chromium with an error.

Aw, Snap!
Something went wrong while displaying this webpage.
Error code: SIGABRT

I couldn't get a clear solution from my research, but it seems that WSL1 can't handle Chromium windowing...

When I ran the same program on a PC with Ubuntu installed, it worked fine, so I took a chance and migrated to WSL2, thinking that WSL1 was increasingly suspect and that it would work if I migrated to WSL2.

Bottom line, WSL2 makes puppeteer work!

Procedure for transition from WSL1 to WSL2

The following article was referred to.

We are already using WLS1.

  • Install Linux kernel updates
  • Set WSL2 as the default version

    • wsl --set-default-version 2
  • Set Ubuntu version to WSL2

    • wsl -l -v: WSL distribution list display
    • wsl --set-version Ubuntu-18.04 2: set to WSL2

WSL1 was changed to WSL2 with only this of

It took a while to run, but it was easier than I expected." With wsl --set-version Ubuntu-18.04 1 you can also revert from WSL2 to WSL1.

VcXsrv (X Server) settings

The following article was referred to.

When I run ipconfig in PowerShell, a new IP address WSL is added, which is the IP address of the WSL2 virtual machine.

PS > ipconfig

Windows IP 構成

イーサネット アダプター vEthernet (WSL):
   接続固有の DNS サフィックス . . . . .:
   IPv4 アドレス . . . . . . . . . . . .: 192.168.140.241
   サブネット マスク . . . . . . . . . .: 255.255.255.240
   デフォルト ゲートウェイ . . . . . . .:

Since WSL1 is part of Windows, the IP address is the same as in Windows, and the IP address specified in the DISPLAY environment variable for WSL1 should be localhost, but for WSL2, the IP address should be that of the above virtual machine.

The IP address of the virtual machine is determined at startup, so instead of writing a solid address, set it dynamically using the following method.

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

Then, when VcXsrv is started with --ac set as its startup parameter, the window can be displayed using VcXsrv (X server) from WSL2 without incident.

Save configuration" allows you to save the configuration file, so that the next time you start VcXsrv, double-click the configuration file.

Docker Configuration

So far, I have installed Docker Desktop on Windows and used it from WSL1.

The following article was used to make Docker Desktop compatible with WSL2.

Caution before migrating Docker to WSL2

  • When Docker Desktop migrates to WSL2, Docker Desktop will delete the previous VM. If you have been using volume in Docker, you need to backup it before the migration.

The procedure for migrating Docker Desktop to WSL2 was simple as follows.

  • First, uninstall Docker from WSL2 and install Docker again.
  • Next, update Docker Desktop. You will be asked a number of questions, but you can configure the settings later, so answer appropriately.

Docker Desktop設定

[Settings] - [General]

Check the "Use then WSL 2 based engine" checkbox to make Docker Desktop WSL2 compatible.

[Settings] - [Resources] - [WSL INTEGRATION]

If only the above is done, the Docker Desktop Docker daemon cannot be accessed from WSL2, so check the "Enable integration with my default WSL distro" checkbox and from which WSL2 distribution you want to access Docker Check the "Enable integration with my default WSL distro" checkbox to determine which WSL2 distribution will access Docker.

You can now access Docker Desktop from WSL2.

Where will WSL2 be built?

I thought WSL2 was a Hyper-V VM, but I can't find any VM that looks like it in the Hyper-V manager.

As mentioned above, when I run ipconfig in PowerShell, the IP address of WSL2 comes up, so WSL2 does exist somewhere....

So WSL2 exists independently as WSL2, using Hyper-V, but separate from the traditional Hyper-V VMs.

Where is the Docker Desktop Docker daemon created?

When I run wsl -l -v in PowerShell, I can see the list of WSL2 distributions, and docker-desktop appears in the list.

PS > wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu-18.04           Running         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2

I see - the Docker Desktop Docker daemon is running as one of the WSL2 distributions, I thought it was running on WSL2 Ubuntu.

Since Ubuntu in WSL2 and Docker Desktop in WSL2 are two different VMs, the configuration that connects them is the aforementioned [Settings]-[Resources]-[WSL INTEGRATION].

Start the traditional Docker Desktop daemon

If you uncheck "Use the WSL 2 based engine" in [Settings]-[General], the Docker Desktop Docker daemon will be launched using a conventional Hyper-V VM.

There appears to be a conventional option available for compatibility.

Start Docker daemon on Ubuntu with WSL2

Since WSL2 is a full-fledged Linux, the Docker daemon seems to work on its own. In fact, when I tried it, it worked.

$ sudo dockerd &
$ docker ps
CONTAINER ID  IMAGE  COMMAND  CREATED  STATUS  PORTS  NAMES

Moreover, when I close Ubuntu and reopen it, the Docker daemon is still there.

$ ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       899  0.0  0.0  67096  4168 ?        S    04:04   0:00 sudo dockerd
root       906  0.6  0.7 1566784 92612 ?       Sl   04:04   0:00 dockerd
root       918  0.7  0.4 1429072 52644 ?       Ssl  04:04   0:00 containerd --config /var/run/docker/containerd/containeroot...

So WSL2 is running behind the scenes even when the window is closed. It is truly a VM.

Then, I sometimes want to reboot, but I can't use the Linux shutdown command, so I shut it down from wsl.exe.

wsl.exe --shutdown

Even without Docker Desktop, you can set up a persistent Docker daemon with WSL2 alone.

So I decided to uninstall Docker Desktop and run the Docker daemon on Ubuntu with WSL2.

Automatically start Docker daemons on Ubuntu with WSL2

However, when I try to run the Docker daemon automatically, systemd doesn't work on WSL2, so I can't run it as it is....

There are several ways to make systemd work with WSL2, but none of them seemed to be standard and troublesome, so I decided to run it manually when Docker is needed. If I really want to use systemd with WSL2, I will think about it then.

Accessing WSL2 files from Windows

In WSL1, I used to access Windows folders from WSL1 via //mnt/, but in WSL2, accessing Windows folders from WSL2 is not recommended because it is slow.

However, it is convenient to share folders between WSL2 and Windows, so access the WSL2 folders from Windows via \\wsl$.

Windows Terminal

I found Windows Terminal in the WSL2 documentation and installed it while I was at it. It looks simple and easy to set up.

The default terminal at WSL was difficult to see the colors, but the Windows Terminal is easier to see because you can change the color theme.

I don't like to mess with the settings too much, but I guess that's the color of PowerShell. So, I set the PowerShell theme to "Campbell Powershell".

Impressions, etc.

This is the end of the transition from WSL1 to WSL2 for MORO.

At first, I was a bit nervous about migrating to WSL2, but it was easier than I thought it would be; I can migrate my WSL1 environment directly to WSL2, and it is just as comfortable to use as WSL1.

Rather, I don't think WSL2 is more stable because it is real Linux. At least, Puppeteer and X server related are more stable with WSL2.

And if the Docker build doesn't look good, you can always try using Docker Desktop again.

So far, I'm happy and satisfied with my transition to WSL2!

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com