If you are a cybersecurity professional, you are probably using the Docker containers constantly. Docker is great for pulling image of a hacking tool, running the container, and after you don’t need the tool, simply destroying the container. In this way you will save time that is required for installing each of the tools separately. Another use case for the Docker containers on Kali Linux is when you need to spin an app to test your tools, methodologies, or just that one specific vulnerability. Today we are going to see how to install Docker on Kali Linux WSL2 and make your life easier.
Kali can be installed on anything, ex. Raspberry Pi. But using the Kali Linux WSL2 and Docker is a something you might find convenient if you are hardcore Windows user. Long gone are the days when you had to bother with virtual machines. Nowadays WSL2 provides performance, and provides a simple way to have Kali Linux running on your Windows desktop. You probably know that creating virtual machines in virtual machines is not possible. This is where the Docker is advantageous – you can have Docker on WSL2 Kali Linux machine.
Without further ado, let’s see how to install it.
How to Install Kali Linux WSL2?
For those of you that do not have the Kali Linux on your machine, we will briefly cover the installation instructions.
This can literally be done in five minutes.
First of all, you need to make sure your Windows is up-to-date. Check the Windows updates (type Windows Updates in the search bar, open the Windows Update settings, check for the updates, and update if necessary).
After that, open the Powershell in the administrator mode. Then execute the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
This might take a while.
And after this you might need a restart. Now after this you will need to enable the virtual machine feature. Once again, open the Powershell as administrator, and execute the following:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Then enable the WSL Linux feature:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
What you should also do, download and install the Linux kernel WSL update. You can download it from there – https://docs.microsoft.com/en-us/windows/wsl/install-manual#step-4—download-the-linux-kernel-update-package.
Lastly, you have to set the default WSL version to the WSL 2:
wsl –set-default-version 2
Restart your machine and you are good to go.
Now open the Microsoft Store, find the Kali Linux app, and install it:
After the installation you will have the Kali Linux WSL on your system. Congratulations! Find the app that was installed in your system, and run it. Update and upgrade the system and you are ready to use it:
sudo apt update && sudo apt upgrade -y
Installing Docker on Kali Linux
If you do have the Kali, let’s continue with the Docker installation.
If you want to have the Docker on Kali Linux WSL2, you must have the Docker installed on your Windows host machine. Download and install the Docker Desktop on Windows.
After this, you have to enable the WSL integration in the Docker settings. Open the Docker desktop application and go to settings.
Click on Resources tab and go to WSL Integration.
Under the “Enable integration with additional distros:” select the kali-linux, then apply the changes by clicking Apply & Restart.
At this point everything is ready, so we can proceed in the Kali Linux CLI. Execute 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
After this, update the OS:
sudo apt-get update
And install the Docker:
sudo apt-get install docker-ce
What should you keep in mind that the command for starting the Docker differs on the WSL. You must use this command:
sudo /etc/init.d/docker start
As a result, you should be able to use the Docker. The following containers were started from the host machine. Now I can see them from Kali Linux:
Not only that, now it is possible to create new containers from the Kali. This will make your work much easier.
That’s it. Congrats, you just installed Docker on Kali Linux WSL2!
Highly passionate about cyber security (penetration testing, bug bounty hunting, cybersecurity in general), and blogging. I am experienced in vulnerability assessments, penetration testing, various security audits, had worked with various clients, most of them were in finance sector.
CompTIA Security+, CEH, CEH Practical, CEH Master, and OSCP certified.
When I run 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
I get:
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
gpg: can’t open ‘–’: No such file or directory
deb [arch=amd64] https://download.docker.com/linux/debian buster stable
There are two commands. First:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add
Just leave the last dash at the end and it the command will run.
Second command:
echo ‘deb [arch=amd64] https://download.docker.com/linux/debian buster stable’ | sudo tee /etc/apt/sources.list.d/docker.list