Install Docker on WSL2 Windows

Adrian Hideki
2 min readFeb 7, 2023

--

Aerial view of a cargo ship (unsplash)

Requisites

  • powershell
  • windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11 (If you are on earlier versions please see the manual install page)

Install WSL2

Run with administrator mode:

wsl --install

Restart the machine.

Get a linux distribution

You can have multiples linux distributions but you need to set one distribution as default

Replace Ubuntu-22.04 with your choosen linux distribution

Run this commmand to list avaliable linux distributions:

wsl --list --online

Choose one distribution and run the code bellow, replacing with your distribution:

wsl --install --distribution Ubuntu-22.04

After install you can see the downloaded distribution with the list command:

wsl --list

Setup credentials to super user.

Install Docker

Replace Ubuntu-22.04 with your linux distribution

Start wsl running the code:

wsl -d Ubuntu-22.04

Login with su and update:

apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release \ net-tools 

mkdir -p /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ | tee /etc/apt/sources.list.d/docker.list > /dev/null

apt-get update | apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

exit

Post installation script to allow current user to run docker commands:

sudo usermod -aG docker $USER && newgrp docker

To access the container from windows get the ip eth0 (inet adress) at wsl environment:

ifconfig eth0

References

Install Linux on Windows with WSL

Install Docker Engine on Ubuntu

Originally published at http://github.com.

--

--