Updated on November 22nd, 2022 in #docker
It’s really fast and only requires a few lines of shell scripting. You won’t need to install systemd inside of WSL 2 either.
Quick Jump: Demo Video
Prefer video? Here’s a recorded version of this tip on YouTube. Besides going over the steps below it covers the “why” and the pros / cons of doing this.
This post covers doing this on Ubuntu 20.04 and 22.04 but it should work with any distro that supports running Docker. I say “should” because I didn’t personally try every single distro but there’s nothing about this that would hint not working on other distros.
You’ll also have options to run Kubernetes directly in WSL 2 if you choose to use KinD or any other tool that lets you run a Kubernetes cluster without Docker Desktop.
Step 1: Uninstall Docker Desktop
Since we’re installing Docker directly inside of WSL 2 you won’t need Docker Desktop installed to make this work.
Step 2: Install Docker / Docker Compose v2 in WSL 2
Here’s the condensed version for Ubuntu and Debian based distros:
# Install Docker, you can ignore the warning from Docker about using WSL
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Add your user to the Docker group
sudo usermod -aG docker $USER
# Install Docker Compose v2
sudo apt-get update && sudo apt-get install docker-compose-plugin
# Sanity check that both tools were installed successfully
docker --version
docker compose version
# Using Ubuntu 22.04? You need to do 1 extra step for iptables compatibility,
# you'll want to choose option (1) from the prompt to use iptables-legacy.
sudo update-alternatives --config iptables
If you’re using a different distro it’s very similar. Docker has docs for the steps above. These steps came from official Linux installation guides: