Windows Subsystem for Linux 2 (WSL 2) Tips, Tricks, and Techniques

Book description

A practical handbook that will help you bridge the gap between Windows and Linux to develop apps that leverage the best features across both ecosystems with seamless interoperability

Key Features

  • Configure and control WSL to suit your needs and preferences
  • Discover tips for working seamlessly between Windows and WSL Linux distros
  • Learn how to work effectively with containers in WSL, as well as how to containerize your development environments with Visual Studio Code to isolate your dependencies

Book Description

Windows Subsystem for Linux (WSL) allows you to run native Linux tools alongside traditional Windows applications. Whether you're developing applications across multiple operating systems or looking to add more tools to your Windows environment, WSL offers endless possibilities.

You'll start by understanding what WSL is and learn how to install and configure WSL along with different Linux distros. Next, you'll learn techniques that allow you to work across both Windows and Linux environments. You'll discover how to install and customize the new Windows Terminal. We'll also show you how to work with code in WSL using Visual Studio Code (VS Code). In addition to this, you'll explore how to work with containers with Docker and Kubernetes, and how to containerize a development environment using VS Code.

While Microsoft has announced support for GPU and GUI applications in an upcoming release of WSL, at the time of writing these features are either not available or only in early preview releases. This book focuses on the stable, released features of WSL and giving you a solid understanding of the amazing techniques that you can use with WSL today.

By the end of this book, you'll be able to configure WSL and Windows Terminal to suit your preferences, and productively use Visual Studio Code for developing applications with WSL.

What you will learn

  • Install and configure Windows Subsystem for Linux and Linux distros
  • Access web applications running in Linux from Windows
  • Invoke Windows applications, file systems, and environment variables from bash in WSL
  • Customize the appearance and behavior of the Windows Terminal to suit your preferences and workflows
  • Explore various tips for enhancing the Visual Studio Code experience with WSL
  • Install and work with Docker and Kubernetes within Windows Subsystem for Linux
  • Discover various productivity tips for working with Command-line tools in WSL

Who this book is for

This book is for developers who want to use Linux tools on Windows, including Windows-native programmers looking to ease into a Linux environment based on project requirements or Linux developers who've recently switched to Windows. This book is also for web developers working on open source projects with Linux-first tools such as Ruby or Python, or developers looking to switch between containers and development machines for testing apps. Prior programming or development experience and a basic understanding of running tasks in bash, PowerShell, or the Windows Command Prompt will be required.

Publisher resources

Download Example Code

Table of contents

  1. Windows Subsystem for Linux 2 (WSL 2) Tips, Tricks, and Techniques
  2. Why subscribe?
  3. Contributors
  4. About the author
  5. About the reviewers
  6. Packt is searching for authors like you
  7. Preface
    1. Who this book is for?
    2. What this book covers?
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Reviews
  8. Section 1: Introduction, Installation, and Configuration
  9. Chapter 1: Introduction to the Windows Subsystem for Linux
    1. What is WSL?
    2. Exploring the differences between WSL 1 and 2
      1. Overview of WSL 1
      2. Overview of WSL 2
    3. Summary
  10. Chapter 2: Installing and Configuring the Windows Subsystem for Linux
    1. Enabling WSL
      1. Checking for the required Windows version
      2. Checking for the easy install option
      3. Enabling the required Windows features
      4. Installing the Linux Kernel
    2. Installing Linux distros in WSL
    3. Configuring and controlling WSL
      1. Introducing the wsl command
      2. Introducing wsl.conf and .wslconfig
    4. Summary
  11. Chapter 3: Getting Started with Windows Terminal
    1. Introducing Windows Terminal
    2. Installing Windows Terminal
    3. Using Windows Terminal
      1. Learning handy keyboard shortcuts
    4. Configuring Windows Terminal
      1. Customizing profiles
      2. Changing the appearance of Windows Terminal
    5. Summary
  12. Section 2:Windows and Linux – A Winning Combination
  13. Chapter 4: Windows to Linux Interoperability
    1. Accessing Linux files from Windows
    2. Running Linux applications from Windows
      1. Piping into Linux
      2. Piping from Linux
    3. Accessing Linux web applications from Windows
    4. Summary
  14. Chapter 5: Linux to Windows Interoperability
    1. Accessing Windows files from Linux
    2. Calling Windows apps from Linux
    3. Calling Windows scripts from Linux
      1. Passing data between PowerShell and Bash
    4. Interoperability tips and tricks
      1. Creating aliases for Windows applications
      2. Copying output to the Windows clipboard
      3. Using symlinks to make Windows paths easier to access
      4. Using wslview to launch default Windows applications
      5. Mapping paths between Windows and WSL
      6. SSH agent forwarding
    5. Summary
  15. Chapter 6: Getting More from Windows Terminal
    1. Customizing tab titles
      1. Setting tab titles from the context menu
      2. Setting tab titles from your shell using functions
      3. Setting tab titles from the command line
    2. Working with multiple panes
      1. Creating panes interactively
      2. Managing panes
      3. Creating panes from the command line
    3. Adding custom profiles
    4. Summary
  16. Chapter 7: Working with Containers in WSL
    1. Overview of containers
    2. Installing and using Docker with WSL
    3. Running a container with Docker
    4. Building and running a web application in Docker
      1. Introducing Dockerfiles
      2. Building the image
      3. Running the image
      4. Rebuilding the image with changes
    5. Introducing orchestrators
    6. Setting up Kubernetes in WSL
    7. Running a web application in Kubernetes
      1. Creating a deployment
    8. Summary
  17. Chapter 8: Working with WSL Distros
    1. Exporting and importing a WSL distro
      1. Preparing for exporting
      2. Performing the export
      3. Performing the import
    2. Creating and running a custom distro
      1. Finding and pulling the container image
      2. Configuring a container ready for WSL
      3. Converting the container to a WSL distro
      4. Running the new distro
      5. Taking it a step further
    3. Summary
  18. Section 3: Developing with the Windows Subsystem for Linux
  19. Chapter 9: Visual Studio Code and WSL
    1. Introducing Visual Studio Code
    2. Introducing Visual Studio Code Remote
    3. Getting started with Remote-WSL
      1. Opening a folder with Remote-WSL
      2. Running the app
      3. Debugging our app
    4. Tips for working with Remote-WSL
      1. Loading Visual Studio Code from your terminal
      2. Opening an external terminal in Windows Terminal
      3. Using Visual Studio Code as your Git editor
      4. Viewing Git history
    5. Summary
  20. Chapter 10: Visual Studio Code and Containers
    1. Introducing Visual Studio Code Remote-Containers
    2. Installing Remote-Containers
    3. Creating a dev container
      1. Adding and opening a dev container definition
      2. Working in the dev container
      3. Running the code
    4. Working with a containerized app in dev containers
      1. Setting up Docker in the dev container
      2. Building the application Docker image
      3. Running the application container
    5. Working with Kubernetes in dev containers
      1. Options for Kubernetes with dev containers
      2. Setting up kind in a dev container
      3. Running our app in a Kubernetes cluster with kind
    6. Tips for working with dev containers
      1. postCreateCommand and automating pip install
      2. Port forwarding
      3. Mounting volumes and Bash history
      4. Using pinned versions for tools
      5. Always Installed Extensions and dotfiles
    7. Summary
  21. Chapter 11: Productivity Tips with Command-Line Tools
    1. Working with Git
      1. Bash completion with Git
      2. Authentication with Git
      3. Viewing Git history
      4. Git information in the bash prompt
    2. Working with JSON
      1. Using jq
      2. Using PowerShell to work with JSON
      3. Summarizing working with JSON
    3. Working with the Azure CLI (az)
      1. Installing and configuring the Azure CLI
      2. Creating an Azure web app
      3. Querying single values
      4. Querying and filtering multiple values
    4. Working with the Kubernetes CLI (kubectl)
      1. Installing and configuring kubectl
      2. Creating a Kubernetes cluster
      3. Deploying a basic website
      4. Querying with JSONPath
      5. Scaling the website
      6. Querying with jq
    5. Summary
  22. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Windows Subsystem for Linux 2 (WSL 2) Tips, Tricks, and Techniques
  • Author(s): Stuart Leeks
  • Release date: October 2020
  • Publisher(s): Packt Publishing
  • ISBN: 9781800562448