, , , ,

Run Linux Containers with Docker Desktop and WSL 2

3–4 minutes
20 comments on Run Linux Containers with Docker Desktop and WSL 2
Docker Desktop WSL 2 Tech Preview

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 the edge version of Docker, and it also requires the Windows 10 Insider Preview builds for Windows 10 version 2004. 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, 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. WSL 2 will be available in Windows 10, version 2004. Today, you will need to install the Windows Insider Slow ring build.

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.

Enable Virtual Machine Platform
Enable Virtual Machine Platform

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
Install WSL 2
Install WSL 2

To find out more about installing WSL 2, check out the Microsoft Docs page.

You also set WSL 2 as the default for all Linux distros:

wsl --set-default-version 2

How to set up Docker and WSL 2

First, you will need to download the Docker Desktop for Windows Edge here. Make sure you already configured all the WSL 2 steps described in the prerequisites, before you install the Docker. 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.

Install Docker for Windows and enable WSL 2
Install Docker for Windows and enable WSL 2

Run the installation wizard, and after a successful installation, the Docker Desktop menu displays the WSL 2 option. You can select WSL 2 from that menu to start and configure the daemon running WSL 2.

Docker for Windows Settings WSL 2
Docker for Windows Settings WSL 2

Now you can run a Linux container using Docker Desktop for Windows, running on Windows 10 using the Windows Subsystem for Linux 2 (WSL 2).

Linux Container on Windows 10
Linux Containers on Windows 10

You can now also do crazy things like run SQL Server on Linux in a Docker container on Windows 10.

SQL Server on Linux Docker Container Windows 10 WSL 2
SQL Server on Linux Docker Container Windows 10 WSL 2

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.

20 responses

  1. pronod bharatiya Avatar
    pronod bharatiya

    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

    1. Thomas Maurer Avatar

      Hi, I am not 100% sure, but I think currently the GPU passthrough is not yet in there. I will need to check.

  2. Owen Avatar

    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.

  3. pronod bharatiya Avatar
    pronod bharatiya

    Thanks…plz do check and if there please guide me in using…

    Regards

  4. Matt Avatar

    When installing Docker, says I need Enterprise version. That is not mentioned anywhere here. WSL2 is running but cant install Docker.

  5. Peter Shanks Avatar
    Peter Shanks

    well that was a waste of 2 hours: “Docker Desktop requires Windows 10 Pro or Enterprise version 15063 to run.”

  6. Kenmore Avatar
    Kenmore

    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?

    1. Thomas Maurer Avatar

      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 :)

  7. Henrique Avatar
    Henrique

    wsl.exe -d Ubuntu-18.04
    The referenced object type does not support the attempted operation

    1. Thomas Maurer Avatar

      Hi Henrique

      Did you install Ubuntu-18.04 from the Windows store?

  8. czaby Avatar

    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.

    1. Thomas Maurer Avatar

      Great that it worked for you! :)

  9. Charisma Riley Avatar
    Charisma Riley

    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?

  10. Gustavo Avatar
    Gustavo

    “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 ?

  11. Anatolie Avatar

    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?

  12. Martin Avatar

    Hi, short question, i can run docker natively in wsl2 now, what is the benefit of this technical preview ?

    thx
    Martin

  13. Eitel Avatar

    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!

  14. Liam Avatar

    Please update guide, screenshots/things do not match and it wont run.

    Some bug about PATH enviroment variable being too long?
    And I don’t see the WSL context in docker context ls.

    Thanks

    1. Thomas Maurer Avatar

      Hi Liam, Thanks for your comment. They updated the Docker client, the UI etc changed a bit. I will update my blog in the next coming days.
      Thanks

  15. Alex Avatar

    Thomas, what are the pros/cons of running Docker in Windows 10 with WSL2 enabled vs Docker in Ubuntu + WSL2 on Windows 10. We had this discussion internally and also other developers wondering about it. Our conclusion is that Docker installed in Ubuntu + WSL2 should run faster. What do you think? We have created this tutorial – https://plumrocket.com/learn/devilbox-docker-wsl2 for a similar setup but also thinking about running docker in Windows to compare if there is any speed difference. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.