Setting Up WSL2

A full guide to Docker in Linux via WSL2

by Nick Sorrell & Garrett Allen

(as of 11-DEC-2019)

Here at IEL, we are absolutely loving WSL2. It has really bridged the gap in getting our Windows devs setup with a primarily Linux-based tech stack. There are a lot of different materials out there on setting up WSL2, but most point to content on different sites. This guide aims to be a one-stop shop for getting WSL2 setup on Windows. It’s going to take a little bit of setup to get there though. In this guide, we will cover the following:

  1. Enable Windows Insider mode on the Slow Ring (moved from Fast Ring in November 2019. One day, this step won’t be necessary)
  2. Installing the latest Docker Edge
  3. Installing Ubuntu / Terminal
  4. Provisioning the Ubuntu VM

Windows Insider Mode

  1. Hit the Windows button and search for “Insider” to find the Windows Insider Program

  2. Link your « Microsoft » account

  3. Select the slow ring

  4. Once this is enabled, go to Check for Updates - a “Preview” build should be available for download

  5. Install the update and restart the computer

  6. Install the features using either a GUI or the CLI

    a. GUI Mode

    1. Hit the Windows button and search for “Turn feature” to find “Turn Windows features on or off”
    2. Find “Windows Subsystem for Linux” and enable it.
    3. Find “Virtual Machine Platform” and enable it.

    b. CLI Mode (Powershell)

    1. Enter these commands:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  1. Restart Windows

Install Ubuntu / Terminal

  1. Open the Microsoft Store and search for “Ubuntu” and install it
  2. Once it is installed, launch it (You will see it do some setup)
  3. In the Microsoft Store, search for “Terminal” and install the Windows Terminal (Preview)
  4. Once you launch the new terminal, you should see a drop down to launch a bash shell via “Ubuntu”
  5. Enable WSL2 by opening a Powershell prompt and typing wsl --set-version <Ubuntu distribution> 2
    1. You can find the name of your installed Ubuntu distribution by typing in wsl -l

Install Docker Edge

  1. Download Docker Edge from this guide
  2. Once you have Docker Desktop running, make sure you follow those steps they mention… we recap those below.
    a. Go to Settings -> General and click the checkbox by Enable the experimental WSL 2 based engine
    b. Go to settings -> Resources -> WSL Integration and flip the radio button next to your Ubuntu distro
  3. Restart your computer… YES AGAIN!
  4. Verify Docker is installed by opening your Ubuntu terminal and typing docker -v - if it says Docker isn’t installed, you have problems (try restarting again in case you missed that step!)

Provisioning Ubuntu

  1. Do not, DO NOT, DO NOT clone or try to run things from within Ubuntu’s /mnt/c/Users/<myuser>. This whole WSL2 setup works on fairly fancy networking, and trying to do file IO within the mount point will lead to significantly degraded performance.

  2. Open your Ubuntu terminal and cd to your Ubuntu home directory (cd ~)

  3. You now have two choices for SSH keys.

    a. Copy from your Windows machine with cp -r /mnt/c/Users/<myuser>/.ssh ~/ and change the mode of the copied private key with chmod 600 ~/.ssh/id_rsa

    b. OR, create new SSH keys inside of Ubuntu and then copy your public key out to GitHub/Bitbucket/Gitlab/YourChoice

  4. Clone your favorite repos and run docker!

Tips

  • Inside of the Ubuntu shell, you can run explorer.exe to open that folder in Windows Explorer
  • You can also run code to open Windows VSCode to edit the contents in that folder