Docker on WSL2 without Docker Desktop

Docker on WSL2 without Docker Desktop

The purpose of this article is to document the steps and issues encountered when installing Docker on a fresh Windows 11 laptop.

Installing WSL2

I have a large SSD on the C drive, so didn't need to worry about moving the WSL storage location.

I installed WSL2 from Powershell using wsl --install, per the following article: https://learn.microsoft.com/en-us/windows/wsl/install.

Note that this was way simpler than issues encountered on older versions of Windows and security issues often encountered in enterprise environments.

Installing Docker

I basically followed these instructions: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04

The exact instructions are duplicated here for reference if this link changes or is broken.

Step 1 - Installing Docker

# First, update your existing list of packages:
sudo apt update

# Next, install a few prerequisite packages which let apt use packages over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common

# Then add the GPG key for the official Docker repository to your system:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Add the Docker repository to APT sources:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Update your existing list of packages again for the addition to be recognized:
sudo apt update

# Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:
apt-cache policy docker-ce

# Finally, install Docker:
sudo apt install docker-ce

# Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running:
sudo systemctl status docker

Step 2 - Executing the Docker Command Without Sudo (Optional)

sudo usermod -aG docker ${USER}
su - ${USER}
groups
sudo usermod -aG docker username