Skip to content

Instantly share code, notes, and snippets.

@Maciek416
Created July 4, 2020 21:54
Show Gist options
  • Save Maciek416/f9301d347b2ca2e93b4bd48fcd8ddd58 to your computer and use it in GitHub Desktop.
Save Maciek416/f9301d347b2ca2e93b4bd48fcd8ddd58 to your computer and use it in GitHub Desktop.
High Performance Docker and Ubuntu Linux on Windows -- without a VM

High Performance Docker and Ubuntu on Windows without Emulation

If you are coming from a Mac setup, running Linux and Docker on Windows may be confusing at first, with advantages which are not immediately obvious.

But there's now a huge difference between Mac and Windows Docker:

Mac, using the official Docker installation:

Mac runs:
 `- OS X, which runs
     `- A *virtual machine* which runs
         `- Linux, which runs
             `- Docker

Windows, with WSL 2:

PC runs:
 `- Windows, which runs
     `- The Linux kernel *directly* (via system call translation)
         `- Docker processes

When you type docker ps on OSX, you are first communicating with a virtual machine which then talks to a Linux process to ask about docker processes.

When you do the same in a bash in WSL 2, you are looking at processes that run directly on your Windows system. An Ubuntu installation on WSL is able to communicate directly with an NVidia GPU.

If you've just built a PC, follow these instructions.

Choosing a Windows 10 Edition.

If you need to use CUDA from Ubuntu to talk to your NVidia GPU

At time of writing, you need to know if you'll want to talk to your NVidia GPU early, because a pre-release version of Windows is required. Please see:

https://docs.microsoft.com/en-us/windows/win32/direct3d12/gpu-cuda-in-wsl

which will direct you to both that version of Windows and other related dependencies that you'll need (possibly drivers etc).

If you don't expect to need to use CUDA from Ubuntu to talk to your NVidia GPU

Install "Windows 10 Home" on a PC. The "Home" edition appears to be enough to run everything in this document. To do most of the work below, you should install Chrome if you aren't already familiar with Edge.

Install WSL2

Use this guide to install WSL2.

Steps and Notes:

  • Keep the guide bookmarked, you'll go back to it after a restart or two.
  • If there's an update to download an MSI file, you're doing that.
  • If there's a failure somewhere while changing the version of WSL to 2, and there's an extra step before trying again, that's normal.

Install Ubuntu from the Microsoft store

Steps and Notes:

  • NOTE: You don't need to create any Microsoft accounts, just close the dialog when it starts nagging you.
  • WSL Linux link to MS Store
  • Choose Ubuntu and install it
  • Click Launch once it's downloaded.
  • Follow the installation instructions, create yourself a user.

Install Docker for WSL2

  • Download from Docker's website
  • When you open the docker config UI, go to Resources ad ensure that Enable integration with my default WSL distro is enabled and that integration with Ubuntu has been enabled. Click Apply & Restart. This will restart docker, which should happen instantaneously.

Launching Bash

Go to the start menu and type bash. That's it. No more cygwyn silliness.

Root permissions

To get root access sudo works.

To get password-free sudo access, edit the sudoers file:

vim /etc/sudoers

Replace YOUR_USERNAME_HERE in the snippet below with your username and update the matching sections in the sudoers file

# User privilege specification
root    ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
YOUR_USERNAME_HERE ALL=(ALL) NOPASSWD:ALL
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
YOUR_USERNAME_HERE ALL=(ALL) NOPASSWD:ALL

Set up Github ssh key

Generate your ssh key for github using the Linux instructions, not the Windows instructions. . Link to Linux instructions

Accessing Ubuntu directories from Windows VSCode: Verify the WSL Extension for VSCode is installed

You might have VSCode installed for Windows. You can continue to use this VSCode if you want, and access directories within the Linux subsystem via an extension.

Install the WSL extension for your Windows VSCode

Using VScode inside Ubuntu

You can also use VSCode inside your Ubuntu by opening up bash and typing code .. Running this will perform a necessary installation step and then launch a VSCode which is separate from your Windows-installed one and which thinks it is inside of an Ubuntu system. This is mainly useful so that when you're working in a bash terminal, you can open code just like you did on OS X.

Install Additional Dependencies "The Ubuntu Way"

Your typical developer dependencies should be installed as if you are on an Ubuntu Linux, because aside from Docker, other software generally does not need to be aware that there's an additional system call translation layer above the Linux kernel.

Other Dependencies that Work as Ubuntu Deps

These should work if installed the Ubuntu way:

  • yarn
  • node
  • npm
  • git
  • Python3 (should already be installed)
  • pip3 (not already installed)
  • Python2 (not already installed
  • pip (not already installed)
  • mysql
  • Go
  • NVidia CUDA (albeit with special instructions, see above).

Network Topology / Geography

To become familiar with your network, you should install some networking utilities:

sudo apt install net-tools
sudo apt install traceroute

Your Linux subsystem has one additional hop to get out to the internet than you do. If you run:

traceroute 8.8.8.8

You should see an additional mshome hop before hitting your home router.

Type the following command:

ifconfig

You should see the loopback device lo and also eth0. The eth0 device will have your IP. It might be something matching the pattern 172.31.xxx.xx. The IP assigned to eth0 is accessible from Windows, and you can reach it with the Chrome you've installed on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment