Windows 10 comes with Windows Subsystem for Linux which provides a seamless experience for running Windows and Linux at the same time. Seamless being the keyword here. Allowing 1) run Windows commands using Linux 2) Run Linux commands through Windows 3) Run HTTP services and access as if everything is accessible through localhost etc. This can be handy if you're a developer and want to work on both Windows and Linux without jumping hoops through VMs.
First, you need to enable the WSL. Settings > Turn Windows features on or off > Windows Subsystem for Linux. Click OK and restart.
Next you have to install a Linux distribution from the Windows Store. Let's install Ubuntu.
After the installation, click on Launch and it's going to set up the distro and create a user. You will be asked to enter a username and a password. This will be the Linux user account that'll be used to login.
At this point we have a working Linux system. You can install all other Linux packages necessary for development through apt-get.
The new Windows Terminal provides quick access to multiple shells with a tabbed interface. You can install this through Windows Store. Here we're going to install it through Chocolatey (a popular package manager for Windows).
Start an administrative PowerShell and execute this powershell-fu (taken from https://chocolatey.org/install). Skip this step if you already have Chocolatey.
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
> choco install microsoft-windows-terminal
to install the new terminal. Reboot.
After installing Docker Desktop for Windows and enabling Kubernetes, you can run the .exe (any .exe for that matter) directly within Ubuntu.
> docker.exe run hello-world
Using the wsl command in Windows you can run any Linux command within a Windows command shell / powershell. Such as
> wsl lsb_release -a
You can also run one command in Windows and pipe the output to a command in Ubuntu which is very nice.
> Invoke-RestMethod http://www.mocky.io/v2/5ebc6fec3100007e005b0b67 | ConvertTo-Json -Depth 5 | wsl jq
Another convenience is you can use localhost for accessing services launched from either Windows, Linux, docker or kubernetes. As you can see below,
Starting up a simple Java service.
Accessing the service from Linux. We're just using localhost and the port 9090 (which my sample service is listening on)
Let's create a simple Ruby on Rails project.
> rails new blog > cd blog > rails server
Access from browser in Windows,
I've installed Docker Desktop for Windows (Edge) and have enabled Kubernetes. After that docker.exe and kubectl.exe can be executed from PowerShell as well as within Ubuntu without having to do anything.
Let's use following example app that runs Wordpress with MySQL on K8S to test out - https://github.com/kubernetes/examples/tree/master/mysql-wordpress-pd
After we deploy everything the app is available through localhost:80 (look at output of kubectl.exe get services wordpress)
WSL provide a nicer way of working with Linux without having to go through the trouble of installing VirtualBox, then installing a guest Linux OS, setup file share and access the system through an SSH server.
Seamless integration works really well when working with standalone commands, interactively piping from one tool-set to the other, working with simple HTTP services and working with containers on Kubernetes.