Run Linux Containers with Docker Desktop and WSL 2
Today, Docker launched the first Tech Preview of the Docker Desktop WSL 2. This means you can now use Docker Desktop and the Windows Subsystem for Linux 2 (WSL2) which is using the hypervisor in the background to run Linux containers on Windows 10. With the significant changes to the Windows Subsystem for Linux 2, you can now take advantage of these improvements with your Docker Desktop client.
Docker Desktop WSL 2 is currently in Tech Preview, and it also requires the Windows 10 Insider Preview builds. That means you should only use for not production environments.
WSL 2 introduces a significant architectural change as it is a full Linux kernel built by Microsoft, allowing Linux containers to run natively without emulation. With Docker Desktop WSL 2 Tech Preview, users can access Linux workspaces without having to maintain both Linux and Windows build scripts.
Docker Desktop also leverages the dynamic memory allocation feature in WSL 2 to greatly improve the resource consumption. This means, Docker Desktop only uses the required amount of CPU and memory resources, enabling CPU and memory-intensive tasks such as building a container to run much faster.
You can find more information about the Tech Preview here.
Prerequisites
To run the Docker Desktop WSL 2 Tech Preview, you will need to set up the Windows Subsystem for Linux 2 (WSL 2) first. You can do that using the following guide, or follow these steps:
Install Windows 10 Insider Preview build 18932 or later.
Install the Windows WSL feature and the Windows Virtual Machine Platform feature running the following commands:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Download WSL Linux distribution based on Ubuntu 18.04 from the Microsoft Store. You can read more about Linux on Windows 10 here. The distribution needs to be set as the default WSL distro.
Make sure that the WSL distro is running in WSL 2 mode. You can check the list of distros installed on your Windows 10 machine, with the following PowerShell command:
wsl -l -v
To set the distro to WSL 2, you can run the following command. Change the name of the distro:
wsl --set-version DistroName 2
To find out more about installing WSL 2, check out the Microsoft Docs page.
How to set up Docker and WSL 2
First, you will need to download the Docker Desktop WSL 2 Tech Preview here. Make sure you already configured all the WSL 2 steps described in the prerequisites, before you install the Docker WSL 2 Tech preview. If you are prompted if you want to use Linux containers or Windows containers during the installation, select Windows containers. If you choose Linux containers, you will have the classic Docker experience with a Hyper-V VM.
Run the installation wizard, and after a successful installation, the Docker Desktop menu displays the WSL 2 Tech Preview option. You can select WSL 2 Tech Preview from that menu to start and configure the daemon running WSL 2.
You can switch between the classic daemon or the Windows Subsystem for Linux 2 with the following commands:
# Switch to classic deamon docker context use default # Switch to WSL 2 docker context use wsl
You can now also do crazy things like run SQL Server on Linux in a Docker container on Windows 10.
I hope this gives you a good overview of how you will be able to run Linux containers on Windows in the future. Again this is still a Tech Preview, and we might see many changes to that feature. If you want to know more, read the full blog post on the Docker page. Also, check out the current Linux Container on Windows documentation. If you any questions, feel free to leave a comment.
Hello Thomas,
I want to use cuda computing through WSL2. My machine had nvidia quadro p3000 gpu. However, i am unable to instal cuda10 driver on ubuntu18.04 distribution on wsl2. Can you help in this please?
Regards
The tech preview installer won’t let me install on win10 home. Its looking for a pro license. I meet the prerequisites on this page i.e wsl2 and ubuntu 18.04. can you clarify the home vs pro situation.
Hi, I am not 100% sure, but I think currently the GPU passthrough is not yet in there. I will need to check.
Thanks…plz do check and if there please guide me in using…
Regards
When installing Docker, says I need Enterprise version. That is not mentioned anywhere here. WSL2 is running but cant install Docker.
well that was a waste of 2 hours: “Docker Desktop requires Windows 10 Pro or Enterprise version 15063 to run.”
In a blog from Docker (https://engineering.docker.com/2019/06/docker-hearts-wsl-2/) they say it will support Home but I am still getting the error that others are saying: “Docker Desktop requires Windows 10 Pro or Enterprise version 15063 to run.” Are we doing something wrong or is Home support still just not out yet?
I think this is currently because of the installer still check for that version. My guess is that with newer versions of the preview it will go away. However, I will try to find out :)
wsl.exe -d Ubuntu-18.04
The referenced object type does not support the attempted operation
Hi Henrique
Did you install Ubuntu-18.04 from the Windows store?
Amazing things happen. Native linux and docker on windows, who would have thought that.
And it actually runs on my home PC. All it costs was abot 9 EUR for a Windows Pro licence, some time to install and a really great guide like this.
Thank you Thomas.
Great that it worked for you! :)
Thomas, this article is awesome! Something I can’t find anywhere, though, is how to then run an actual WSL 2 container. I know we are required to be using Ubuntu 18.04 as our default installation, so how does that work? Do I just ‘docker context use wsl’ and then ‘run ubuntu’? Or how does that work?
“You can now also do crazy things like run SQL Server on Linux in a Docker container on Windows 10.”
I already can run SQL Server 2017 on Linux container with Docker on Win10 Pro without WSL2, so what is the change ?
Searching for a fast development environment today I set up Docker with WSL2 on windows 10.
Then I installed DevilBox http://devilbox.org/ and the first project – Shopware 5. I hoped that here Shopware will be faster then on virtual machines on Hyper-V and VirtualBox but I am totally disapointed.
Here Shopware is MUSH slower!
Everywhere I read about WSL2 is written as much faster than SWL1 and Docker also emphasized the performance for WSL2 but I don’t see it being that way. Maybe some settings need to be made in Daemon Settiins in Docker?
Hi, short question, i can run docker natively in wsl2 now, what is the benefit of this technical preview ?
thx
Martin
Thomas, thanks for a great article. Is it possible to run SQL Server 2019 big data cluster in WSL2? I am looking for a simple way to test both SQL Server and Spark / HDFS on a single node. SQL Server 2019 big data cluster runs on a Kubernetes cluster, so I thought that a good approach, other than spinning a Linux box would be to use WSL2. Im looking for a good article that would explain this, but have not found one. Any ideas? Thnx!