Here is how you get set up on WSL2 with for example Ubuntu 24.04 or perhaps 24.10 if you're one of the pain enjoyers like me.

sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [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
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER

Now spin up a Powershell and shutdown WSL for the group changes to take effect.

wsl --shutdown

Go ahead and start Ubuntu again, then start the docker service and test a docker ps to ensure we have a connection to the socket.

sudo service docker start
docker ps -a

There you go!