DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Bart Robertson
Bart Robertson

Posted on

Install Docker on Windows Subsystem for Linux v2 (Ubuntu)

Install Docker on Windows Subsystem for Linux v2 (Ubuntu)

The Windows Subsystem for Linux v2 (WSL2) is available in preview for Windows 10 users. WSL2 is a substantial improvement over WSL and offers significantly faster file system performance and full system call capabilities. Which means we can finally run dockerd in WSL!

WSL2 is currently only available as a preview feature through the Windows Insider program. WSL2 requires Windows 10 build 18917 or higher which currently requires the "Fast Ring" of Windows Insider.

If you're not ready to run a fast ring preview on your dev box, you can download an ISO and experiment with WSL2 in a VM. Windows Insider ISOs are available here:

Setup WSL2

Setup instructions for WSL2 are available here: Make sure to install the Ubuntu distro from the Microsoft Store

Once setup, start a command prompt and run the following command to verify Ubuntu is set to version 2

# Set WSL to default to v2
wsl --set-default-version 2

# check the version
wsl -l -v

# Output should show Ubuntu and version 2
# if not, you can upgrade the distro
# this usually takes 5-10 minutes
wsl --set-version Ubuntu 2

Install Docker

From WSL bash, run the following commands to setup Docker. These are nearly identical to setting up on an Ubuntu VM.

# update the package manager and install some prerequisites (all of these aren't technically required)
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common libssl-dev libffi-dev git wget nano

# create a group named docker and add yourself to it
#   so that we don't have to type sudo docker every time
#   note you will need to logout and login before this takes affect (which we do later)
sudo groupadd docker
sudo usermod -aG docker ${USER}

# add Docker key and repo
curl -fsSL | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"

# (optional) add kubectl key and repo
curl -s | sudo apt-key add -
echo "deb kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

# update the package manager with the new repos
sudo apt-get update

# upgrade the distro
sudo apt-get upgrade -y
sudo apt-get autoremove -y

# install docker
sudo apt-get install -y docker-ce

# (optional) install kubectl
sudo apt-get install -y kubectl

# (optional) install latest version of docker compose
sudo curl -sSL`curl -s | \
grep "compose/releases/tag" | sed -r 's|.*([0-9]+\.[0-9]+\.[0-9]+).*|\1|p' | head -n 1`/docker-compose-`uname -s`-`uname -m` \
-o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose

Finalizing setup

Currently, Docker doesn't auto start, so you have to start the service each time. The below command will patch your .profile to start Docker each time you login.

echo "sudo service docker start" >> ~/.profile

# exit and then restart WSL

Once you exit and restart WSL (just run "wsl" from the command prompt or Windows Run command), Docker should work correctly. To test, run the following command from WSL bash.

docker run -it hello-world


I prefer WSL to always start in my home directory (~), so I use the following to add that to my .profile

echo "cd ~" >> ~/.profile

Install Azure CLI

# add Azure CLI key and repo
curl -sL | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg
CLI_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] ${CLI_REPO} main" | sudo tee /etc/apt/sources.list.d/azure-cli.list

# update the package manager
sudo apt-get update

# install Azure CLI
sudo apt-get install -y azure-cli

Install dotnet core

# add the dotnet core repo
echo "deb [arch=amd64] bionic main" | sudo tee /etc/apt/sources.list.d/dotnetdev.list

# update the package manager
sudo apt-get update

# install dotnet core
sudo apt-get install -y dotnet-sdk-2.2

Top comments (3)

bholub profile image
Brian Holub

Can you explain what the "Configuring grub-pc" options mean and what the consequences are? Thanks!

siudeks profile image
Sławomir Siudek

install latest version of docker compose does not install docker-compose

corleroux profile image
Cor le Roux

As per the docker documentation:

sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.