26

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
  • 375
  • 1
  • 4
  • 7
  • I'm no expert in any of them to write an answer, but my vote goes to Docker. The reason is that Docker implies virtualization, so things should just work. WSL on the other hand is full of bugs. It does work for benchmarks, fun, and mostly development; but if you're about to deploy something serious, this is not your choice, at least not yet. – Hi-Angel Nov 01 '17 at 22:16

4 Answers4

24

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,966
  • 16
  • 19
  • I think this answer refers to WSL, WSL 2 runs a custom linux kernel, that interfaces with windows. I believe that custom windows linux kernel runs in a VM. – Jordan Stewart Feb 13 '20 at 07:24
  • 1
    It did. Just posted an update to better reflect our WSL2 reality :) – Rich Turner Feb 19 '20 at 00:18
  • I'm not sure this answers the main question: What are the differences of running Linux on Windows through WSL2, vs. Docker? – a06e Aug 01 '23 at 11:47
5

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
  • 15,380
  • 6
  • 51
  • 79
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.

mangoTango
  • 83
  • 1
  • 5
  • 3
    You don't need to be toxic, especially at the end. Rather, please tell us what you did to research the cause of the problems you're facing and whether they are known issues or not and if someone is working on fixing them or not. I'm sure they are though. And you don't need to uninstall windows, you just need to install hyper-v manager and quick install Ubuntu and you're set for a Linux development environment if you want to work from inside a virtual Linux Desktop. Otherwise keep using WSL and wait for your issues to be fixed. 97 MB/s is not that slow. – Paul-Sebastian Manole Feb 09 '19 at 21:34
  • 2
    AFAIK the speed issues are related to Windows file access subsystem and a workaround is in the works. – Paul-Sebastian Manole Feb 09 '19 at 21:35
  • 1
    WSL still seems slow. But it does have a very fast start up time, and allow the use of common linux cli tools. Mapping the linux and windows file system seems complicating. – Jordan Stewart Feb 13 '20 at 07:26
  • It has gotten perceptibly faster. However I tried using miniconda and installing packages and it was still a little slow. – mangoTango Feb 21 '20 at 04:56
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.

GabrielO
  • 11
  • 2
  • Did you perhaps mean to post this answer on a different WSL question? This doesn't look like it has anything to do with this particular question. This question wasn't looking for a "solution", but rather an "explanation" of various options. – NotTheDr01ds May 01 '22 at 02:44
  • @NotTheDr01ds - Regarding the last paragraph of the main request ("So I will appreciate any information about these two."), I'm trying to present another way of achieving the same goal, but with less side effects. In other words, I'm broadening the scope of investigation and with the bonus of a tested solution. Just edited the answer to be more clear. Thanks! – GabrielO May 01 '22 at 12:36
  • Fair enough - Thanks for the explanation! – NotTheDr01ds May 01 '22 at 13:21
  • @NotTheDr01ds - would you mind to remove the downvote? Thank you. – GabrielO May 01 '22 at 17:09
  • I never downvoted it. I wouldn't downvote on an answer I just thought was out of place, and especially not on a new user. I'd guess it was someone reviewing from the "First answers" review queue. Tell you what, I'll give you a "Welcome to AU" upvote, though. It will show as "0" score on the question (until you have enough rep to see upvotes/downvotes), but you'll notice that your rep is now (I'm guessing) 9 -- The original "1", then +10 for my upvote, and -2 (I think) from the downvote. – NotTheDr01ds May 01 '22 at 19:52
  • Thanks, really appreciated. :) – GabrielO May 01 '22 at 21:40