Skip to content

Instantly share code, notes, and snippets.

@adrianhideki
Last active February 7, 2023 15:11
Show Gist options
  • Save adrianhideki/f532f67dd73bcc268a47c059e5a19b1c to your computer and use it in GitHub Desktop.
Save adrianhideki/f532f67dd73bcc268a47c059e5a19b1c to your computer and use it in GitHub Desktop.
Install Docker on WSL2 Windows

Install docker on WSL2

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:

sudo su
apt-get 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 \
  $(lsb_release -cs) stable" | 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

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

ifconfig eth0

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment