WSL2 Wahala

Posted: 08 October, 2020 Category: rough notes Tagged: WSL1WSL2docker

Upgrading from WSL1 to WSL2

Well I survived the upgrade, but here are some quick notes about the holes I fell into.

  • First off, the upgrade was a bit finnicky:

    • You'll need to restart it at some point. Restarting on windows 10: find the service LxssManage and restart THAT.
    • You may want to use wsl -l -v to see what flipping versions of WSL things are even running. This is what helped me realise that in spite of several upgrade calisthenics, I had somehow managed to NOT upgrade anything.
    • converting WSL 1 to 2: after you've done all the steps, you must run wsl --set-version Ubuntu 2 to convert the existing distro (Ubuntu in my case) to wsl version 2! The operative word here is convert: this can be slow and you are generally advised to just install a new distro instead of converting the existing distro's file sytem or whatever.
    • Prolly wanna ensure any future distros installed under wsl are version 2, so run wsl.exe --set-default-version 2
  • Also: upgrading breaks your hot module reloading so badly that you will cry and want your mommy. I'd clung on to WSL 1 for so long that I was only now running into this... and like a lot of folks, I hadn't read this before setting out on my upgrade journey. So:

    • If you (foolishly?) like to keep your files on windows, out of old habitude, AND decide to upgrade to WSL2, know that you are entering a special place in hell.
    • If you're not keen on special places in hell, the solution seems to be to just move your files (repos) wholesale into WSL2 and let your linux distro calmly nurse them the way only a linux distro can, sans mounts. Having done this for a few projects, I can tell you it's definitely the way to go.
  • On the other hand, it makes docker niftier, related to which:

    • DOCKER in WSL actually relies on the docker daemon running in windows, believe it or not. Ikr? So in order to make your shiny new WSL2 distro work with your shiny new Docker Desktop that leverages WSL2:

      • go to settings in docker desktop
      • in Settings > General tab, make sure the Use the WSL2 based engine is checked
      • in Settings > Resources > WSL Integration, make sure docker can see your WSL2 distros and that you've checked all the boxes / turned on all the integrations with your WSL2 distros
      • this is crucial: for everything to work, stop setting the DOCKER_HOST env variable. In fact, go ahead and do unset DOCKER_HOST and then to be extra sure, also remove that from your ~/.bashrc and restart your shell.
      • run docker info from inside your wsl terminal and your docker will oblige with a screenful of glorious info! You are connected! Woohoo!

In short, waaay more wahala than I had initially bargained for. I am not complaining though... especially about the HMR shenaniganry because I wouldn't know an inotify API (seemingly the root cause) if it slapped me with a wet fish. I await whatever voodoo incantations inter-OS devs need to whisper at it.

(Googles, now curious...)

Oh look, it has a man page.