Native support for Docker on the Windows Subsystem for Linux is coming in version 2. However, if you are looking for a stop gap that does not involve installing beta versions of Windows 10, we have a solution courtesy of Nick Janetakis.
Please note we’re assuming you have installed Docker Desktop and are using the Ubuntu distribution in WSL. I have recorded instructions to install Ubuntu on Windows 10 with WSL in case you haven’t done it yet.
Note: As of 14th May 2020, Ubuntu 20.04 on WSL is suffering from multiple issues (https://bugs.launchpad.net/ubuntu/+source/linux-oem-5.6/+bug/1873441, https://forums.docker.com/t/cant-install-docker-on-ubuntu-20-04/93058, https://github.com/microsoft/WSL/issues/5125). Our recommendation is to use Ubuntu 18.04 until these issues are fixed.
First open the general settings for Docker Desktop and select “Expose daemon on tcp://localhost:2375 without TLS”. This will allow you to connect to the Windows Docker Desktop application from the WSL. Restart Docker Desktop for the change to take effect.
Then update your package list and your installed packages:
sudo apt update -y && sudo apt upgrade -y
Install the packages required to add HTTPS repositories:
sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
Download the Docker repository PGP key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add the Docker repository to apt:
sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
Update your package lists and install Docker CE:
sudo apt update -y && sudo apt install docker-ce
Set the docker cli to connect to the docker daemon:
echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc
Check you can connect to the Windows Docker daemon:
Hack the WSL configuration to avoid mounting issues, see Nick Janetakis’s explantion for more information as to why. Edit
/etc/wsl.conf so it looks like:
[automount] root = / options = "metadata"
Reboot Windows and try
docker run hello-world to see everything is working correctly.