Docker on Linux on WSL 2 on Windows!

By | September 21, 2020

Confession time: Despite my best intentions (and all of the time I’ve spent studying for AWS certifications), I still *stink* at Linux! I mean I can get around, edit things, start/stop services, but I don’t understand it in the fundamental way that I understand windows. I have been meaning to get better at it (honest!)… but for some reason there’s always something else that needs to get done.

I’ve installed Linux distros onto VMware Workstation about a dozen times with the best of intentions, but then what happens? Life happens! Some tight timeline thing comes along and I start to struggle with the OS & not the project. I throw my hands up and switch back over to good old windows where I know how to move around at least.

I told you that story to preface this article. I’m currently taking the free Introduction to OS Command Injections course over at Cybr. During the lab setup phase the instructor helps to setup your homelab by:

  1. Installing VirtualBox
  2. Downloading the Kali Linux distro
  3. Running that ISO in VirtualBox

This was when I decided that I would try to use the Windows Subsystem for Linux (WSL 2) and the Kali distro from the Microsoft Store instead.

Because I stink at Linux (see above…) I ran into several issues. Here is a step by step for getting Docker on Kali Linux on WSL 2 on Windows up and running!

Install WSL 2 (make sure you are on Windows 10 version 2004, build 19041 or higher!):

  1. Run Powershell as Admin:
right click on Powershell Icon, run as admin

2. Enable WSL, from PowerShell type:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Download the Linux kernel update package

Set WSL 2 as your default version:

wsl --set-default-version 2

Install Kali Linux from MS Store

Type “store” in the start menu:

Microsoft Store window
Yeah, I’m still not used to it either…

Put Kali Linux in the search bar and go get it!

Kali Linux in MS Store

From the Kali CLI, perform the following tasks:

sudo apt update && sudo apt upgrade -y

sudo apt install kali-desktop-xfce -y
sudo apt install xrdp -y
sudo service xrdp start

Install Docker Desktop for Windows

Once this is done, open settings and change resources so that WSL integration is ON for all the distros that you want to run docker in:

Docker Settings panel
Docker Desktop Settings Panel

Now that this is done, go back into the Kali CLI and input the following commands:

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

echo 'deb [arch=amd64] https://download.docker.com/linux/debian buster stable' | sudo tee /etc/apt/sources.list.d/docker.list

sudo apt-get update

sudo apt-get install docker-ce

Note: Instead of using 

sudo systemctl start docker 

use: 

sudo /etc/init.d/docker start 

OK! Now that I’ve got that sorted out, I can create my 2 docker environments and start learning about OS command injections:

Desktop with all containers running