29

I understand that it is currently possible to run Ubuntu on Windows 10 in two different ways:

  1. Using the Windows Subsystem for Linux (WSL).
  2. Installing docker for Windows 10, and use a container with Ubuntu.

However, I could not find an easy to understand explanation of what are the differences between them (talking about applications), as well as advantages and disadvantages.

I found a post talking about using docker on WSL: Ubuntu via (Windows Linux Subsystem) and Docker. But I'm talking about using it directly on Windows 10. So I will appreciate any information about these two.

alvgom
  • 405

4 Answers4

26

Updated 2020/02/18 to reflect changes introduced in WSL2

Hi! Microsoft PM working on WSL & Command Line here.

WSL allows you to run native, unmodified Linux ELF-64 binaries directly on Windows, and enables you to run your favorite Linux tools atop your Windows "host" OS.

WSL1 took an approach of adding a Linux syscall compatible layer at the top of the NT kernel, allowing Linux binaries to run atop NT, sharing the same underlying filesystem, networking, process list, etc. as the host OS.

The soon to be released WSL2, on the other hand, runs distros' binaries within Linux containers, atop a real Linux kernel, inside a lightweight VM that allocates only the RAM needed by the apps it runs, and then releases freed RAM back to the host OS. This provides 100% Linux compatibility, and allows your Linux tools to run with near native performance, and consumes minimum resources necessary from the host, ensuring your machine runs fast and smoothly.

Prior to WSL2, one could run the Docker client in WSL1, using it to drive Docker for Windows running atop Hyper-V on the local host, or to manage a remote Docker server. But one cannot run Docker Engine on WSL1 for many technical reasons.

However, you can do the same in Docker on WSL2, but you can also run the Docker Engine itself atop WSL if you prefer. This is, Docker's preferred and future path for running Docker on Windows desktop.

To learn more about WSL, review the videos & docs here: https://aka.ms/learnwsl

Rich Turner
  • 1,986
11

I understand that it is currently possible to run Ubuntu on Windows 10 in two different ways.

... what are the differences between them (talking about applications), as well as advantages and disadvantages.

At the time the question was asked, there were actually three ways to run Ubuntu on Windows 10:

  • Ubuntu on WSL (version 1 at the time)
  • Ubuntu in a Docker Container using Docker Desktop with the Hyper-V backend.
  • Ubuntu in a virtual machine

Currently, there are two additional options:

  • Ubuntu on WSL2
  • Ubuntu in a Docker Container using Docker Desktop with the WSL2 backend.

All five of these options are currently viable, and most are still useful in certain situations. All of these options allow ELF64 binaries to run unmodified in an Ubuntu ecosystem.

Ubuntu running under Docker Desktop with the WSL2 backend

Best for:

  • Building/developing Docker containers with an Ubuntu base (or any other base, but this question is specifically about running Ubuntu).
  • Single-purpose tools that will be distributed as containers that require or are best run on Ubuntu.

Weaker when:

  • Just about anything else. This isn't a bad thing -- Docker is a great containerization tool, but containers aren't meant to be a way to "run Ubuntu" in a general sense.*

    For starters (and probably most importantly), containers are built up in an overlay filesystem that adds a layer each time you make a change. So each sudo apt update && sudo apt upgrade generates an entirely new layer on top of the old. This would be an incredibly wasteful way to run a "general use" system.

    Containers are usually rebuilt each time you need to make a change to the underlying system.

    Also, when you are running Docker Desktop on Windows, you are almost always going to be using the WSL2 backend anyway. It's much more efficient to just use Ubuntu on WSL2 in that case.

Summary:

  • Docker Desktop with the WSL2 backend is a fantastic tool for building containers using Docker.
  • It combines the low-resource utilization of the WSL2 subsystem with ability to create reproducible, rapid-start Ubuntu (or other) containers.
  • It is not recommended for running a general-use Ubuntu system under Windows (or anywhere else).
Ubuntu on WSL2

Best for:

  • Development tasks, including GPU-compute
  • Command-line Linux tools and shells
  • System-administration tasks such as ssh client, Ansible, AWS/Azure/Google Cloud administration, etc.
  • Mixing and matching Windows and Linux tools through WSL interop.

Weaker when:

  • You need frequent access to files on Windows drives that can't be moved to Ubuntu/WSL2 filesystem, since WSL2 is much slower when accessing Windows files.
  • You need access to physical hardware.
  • The applications you are using (or directions you are following) utilize Systemd, which is not easily supported in WSL (1 or 2).
  • You need to access services running in Ubuntu from other devices/computers. For instance, running a web server in WSL2 will require you to set up some type of port forwarding to reach the service.
  • You need access to a Desktop environment (Gnome, Xfce4, etc.)

Summary:

  • Operates in a "container" of sorts under the WSL2 VM
  • The WSL2 VM runs a real Linux kernel provide by Microsoft
  • The kernel is open-source
  • You can build your own kernel from source
  • Primarily a command-line first environment
  • On Windows 11, supports graphical Linux applications out-of-the-box
  • On Windows 10, can run graphical Linux applications with additional configuration
  • Extremely fast startup, resource usage
  • Side-note: It is possible to run Docker Engine directly on Ubuntu on WSL2, but the recommended way is still Docker Desktop.
Ubuntu in a virtual machine

Best for:

  • Simulating a "real" computer with its own network stack, virtual hardware, console, etc.
  • Services or tasks which require or are simplified by Systemd
  • Running a full Desktop environment, especially Gnome since it heavily utilizes Systemd.
  • Learning tools like Grub, disk partitioning, networking, and others which work better with real or virtual hardware.

Weaker when:

  • You need integration with Windows tools such as PowerShell
  • You need/want quick access to Ubuntu from within Windows. WSL's rapid startup and lean resource utilization are better for quickly launching an Ubuntu environment.

Summary:

  • Running in a VM is the decades-old way of running Ubuntu on Windows that predates all of the other methods here.
  • It provides virtual hardware that allows Ubuntu to run "as expected" in almost every case.
  • Interesting side-note: You can actually run Ubuntu inside a VM such as QEMU/KVM inside WSL2 as long as your system supports nested virtualization, with a reasonably level of performance.
Ubuntu on WSL1

Best for:

  • Systems without a CPU capable of providing virtualization -- WSL1 can still provide an Ubuntu distribution running with native ELF64 binaries at a reasonable level of performance without needing virtualization support.
  • Accessing files on Windows drives. Performance is roughly 10x faster than WSL2 for this.
  • Tasks which require inotify support for files on a Windows drive, as this is not supported currently under WSL2.

Weaker when:

  • The application you are running requires "lesser utilized" kernel capabilities. Since kernel syscalls are "translated" to the Windows API, not all capabilities are supported. Features such as Cgroups, namespaces, and others are not supported on WSL1 (but are on WSL2 and all other methods listed here).

  • The applications you are using (or directions you are following) utilize Systemd, which is not easily supported in WSL (1 or 2).

  • You need access to a Desktop environment (Gnome, Xfce4, etc.)

Summary:

  • WSL1 provides a similar level of tight integration with Windows as WSL2, and is still preferable for some tasks.
  • While it runs as a "translation layer" (sort of a "reverse-Wine"), the compatibility level is still fairly high -- It supports around 85% of syscalls that cover around 98% of common development tools.
  • Because it does not support Cgroups, namespaces, and other kernel features that are used for containerization, Docker will not run directly on WSL1.
Ubuntu in Docker Desktop using the Hyper-V backend

Best for:

  • Developing Docker containers that utilize Ubuntu on the rare system that will run Hyper-V but not WSL2. This would be unusual.

Weaker when:

  • Any other scenario. I really don't know of anyone using this scenario for anything but testing Docker when WSL2 isn't working for some reason.
NotTheDr01ds
  • 22,082
3

That is correct. One thing that you do fail to mention is that WSL is currently rather slow in io even with a fast ssd/lots of ram/8-core xeon cpu. This is still a problem in 01/2019. I just did a ray@DESKTOP-O0MT13B:/mnt/c/Users/rayjh$ dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync on my workstation with a samsung SSD and only got 97.6 MB/s.

Running bare metal ubuntu LTS this box will get SEVERAL times that. Never mind the endless problems when you try to combine WSL with VSCODE.

I'm wiping windows 10 off of here and installing ubuntu 18.04LTS.

0

One of the biggest WSL issues is exactly IO, specially when mounting different filesystems. For instance, placing your files in Windows and mapping it through Docker Compose is terribly slow. Another way of working with WSL + Docker is to move your files to the box and connect remotely, like Visual Studio Code does with the Remote-WSL plugin (https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl). That way, you get rid of the overhead of unnecessary mounting points, which in fact, are nothing but network shares.