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:
- Enable Windows Insider mode on the Slow Ring (moved from Fast Ring in November 2019. One day, this step won’t be necessary)
- Installing the latest Docker Edge
- Installing Ubuntu / Terminal
- Provisioning the Ubuntu VM
Windows Insider Mode
-
Hit the Windows button and search for “Insider” to find the Windows Insider Program
-
Link your « Microsoft » account
-
Select the slow ring
-
Once this is enabled, go to Check for Updates - a “Preview” build should be available for download
-
Install the update and restart the computer
-
Install the features using either a GUI or the CLI
a. GUI Mode
- Hit the Windows button and search for “Turn feature” to find “Turn Windows features on or off”
- Find “Windows Subsystem for Linux” and enable it.
- Find “Virtual Machine Platform” and enable it.
b. CLI Mode (Powershell)
- Enter these commands:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
- Restart Windows
Install Ubuntu / Terminal
- Open the Microsoft Store and search for “Ubuntu” and install it
- Once it is installed, launch it (You will see it do some setup)
- In the Microsoft Store, search for “Terminal” and install the Windows Terminal (Preview)
- Once you launch the new terminal, you should see a drop down to launch a bash shell via “Ubuntu”
- Enable WSL2 by opening a Powershell prompt and typing
wsl --set-version <Ubuntu distribution> 2
- You can find the name of your installed Ubuntu distribution by typing in
wsl -l
- You can find the name of your installed Ubuntu distribution by typing in
Install Docker Edge
- Download Docker Edge from this guide
- Once you have Docker Desktop running, make sure you follow those steps they mention… we recap those below.
a. Go toSettings -> General
and click the checkbox byEnable the experimental WSL 2 based engine
b. Go tosettings -> Resources -> WSL Integration
and flip the radio button next to your Ubuntu distro - Restart your computer… YES AGAIN!
- 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
-
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. -
Open your Ubuntu terminal and cd to your Ubuntu home directory (cd ~)
-
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 withchmod 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
-
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