Installing Docker CE in WSL2

docker wsl2 linux windows

Docker in WSL2

To get it running on Windows without needing a Docker Desktop license I had to do the following:

Firstly I installed docker (not entirely sure this is needed since it didn't come with the actual Docker CLI)

sudo apt install docker

Now we need to add the Docker key to the apt sources.list so we can grab docker-ce (community edition) and more from the Docker guys:

sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

Update the sources.list with the new key and install it in apt.

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Now we can finally grab Docker itself!

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Test if Docker is there;

sudo docker ps

If it's there you can use it with sudo. If you want to skip having to use the sudo command every time you can add yourself to the docker group.

sudo usermod -aG docker $USER

Restart your shell and you should be able to just run docker ps now without having to add sudo.

Test if everything works by running

docker run hello-world

Previous Post