<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Paddy Morgan</title>
    <description>The latest articles on Forem by Paddy Morgan (@paddymorgan84).</description>
    <link>https://forem.com/paddymorgan84</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F596669%2F48bf94f5-fac3-4753-b78b-78eaf8b35451.jpeg</url>
      <title>Forem: Paddy Morgan</title>
      <link>https://forem.com/paddymorgan84</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/paddymorgan84"/>
    <language>en</language>
    <item>
      <title>Enhancing Terraform with Terragrunt</title>
      <dc:creator>Paddy Morgan</dc:creator>
      <pubDate>Fri, 23 Apr 2021 08:04:59 +0000</pubDate>
      <link>https://forem.com/paddymorgan84/enhancing-terraform-with-terragrunt-540o</link>
      <guid>https://forem.com/paddymorgan84/enhancing-terraform-with-terragrunt-540o</guid>
      <description>&lt;p&gt;Over the last few months, I've become very familiar with using &lt;a href="https://www.terraform.io/"&gt;Terraform&lt;/a&gt; to deploy infrastructure across multiple cloud vendors. I'm a big fan of it, but some of its idiosyncrasies can be frustrating, particularly as the size of your project begins to increase.&lt;/p&gt;

&lt;p&gt;Fortunately, there's a tool that helps to mitigate many of these issues; &lt;a href="https://terragrunt.gruntwork.io/"&gt;Terragrunt&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Below is a short post on some of the features of Terragrunt that I've found useful in my projects. I've also created an &lt;a href="https://github.com/paddymorgan84/terragrunt-tutorial"&gt;example&lt;/a&gt; that can hopefully better illustrate the benefits I'm writing about. Provided you have the following, you should be able to spin up the example resources yourself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://azure.microsoft.com/en-gb/free/"&gt;An Azure account&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli"&gt;The Azure CLI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.hashicorp.com/tutorials/terraform/install-cli"&gt;Terraform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://terragrunt.gruntwork.io/docs/getting-started/install/"&gt;Terragrunt&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What is Terragrunt?
&lt;/h2&gt;

&lt;p&gt;Terragrunt is a thin wrapper that overlays Terraform that allows you to avoid having large amounts of repetition in your infrastructure as code, as well as helping with Terraform modules and remote state.&lt;/p&gt;




&lt;h2&gt;
  
  
  DRY Providers
&lt;/h2&gt;

&lt;p&gt;You can use the &lt;a href="https://terragrunt.gruntwork.io/docs/reference/config-blocks-and-attributes#generate"&gt;generate block&lt;/a&gt; in your root &lt;code&gt;terragrunt.hcl file&lt;/code&gt; to inject common configuration files. One of the most common uses for it is to use it to generate your provider configuration. By adding the generate block in your root, you can delete the &lt;code&gt;provider.tf&lt;/code&gt; files in your other directories. Whenever any Terragrunt command is called, the providers will be copied to the appropriate directories.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The change in my tutorial repo can be found &lt;a href="https://github.com/paddymorgan84/terragrunt-tutorial/commit/fec1da99dee5d0ff985de452175a586dc2348efa"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Executing on multiple modules
&lt;/h2&gt;

&lt;p&gt;When you use Terraform, you can't run commands against all of your modules at the same time. With Terragrunt, you can. If you add a &lt;code&gt;terragrunt.hcl&lt;/code&gt; file to each module, you can run commands using &lt;code&gt;run-all&lt;/code&gt; from root to run every module. Terragrunt recursively looks through each of your directories for the presence of that file, and if it finds it, will run the command you've included with &lt;code&gt;run-all&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example, if you wanted to apply all of the modules in this solution, you can run the following commands from the root of your repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terragrunt run-all init
terragrunt run-all apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you subsequently wanted to tear down everything you had, you can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terragrunt run-all destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Parallelism
&lt;/h2&gt;

&lt;p&gt;Another nice feature of Terragrunt is when you run commands such as &lt;code&gt;run-all&lt;/code&gt;, it will run as many of the modules that have &lt;code&gt;terragrunt.hcl&lt;/code&gt; files as possible in parallel. Terragrunt doesn't put a constraint on this, which is a blessing and a curse. Your infrastructure deployment times will be faster, but if you're not careful you can get rate limited by your provider, so use it with caution.&lt;/p&gt;

&lt;p&gt;If you do start to experience rate limits, you can specify the &lt;code&gt;--terragrunt-parallelism&lt;/code&gt; flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terragrunt run-all apply &lt;span class="nt"&gt;--terragrunt-parallelism&lt;/span&gt; 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The change in my tutorial repo can be found &lt;a href="https://github.com/paddymorgan84/terragrunt-tutorial/commit/fec1da99dee5d0ff985de452175a586dc2348efa"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  DRY CLI Flags
&lt;/h2&gt;

&lt;p&gt;It's quite likely that when you run Terraform you're running commands with extra arguments. For example, you may have some common variables that you pass for each module, or you may want to restrict parallelism to avoid rate limiting.&lt;/p&gt;

&lt;p&gt;With Terragrunt, you can specify an &lt;code&gt;extra_arguments&lt;/code&gt; block that makes sure that commands that you repeat each time are always included.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;terraform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;# Ensures paralellism never exceed two modules at any time&lt;/span&gt;
  &lt;span class="nx"&gt;extra_arguments&lt;/span&gt; &lt;span class="s2"&gt;"reduced_parallelism"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;commands&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;get_terraform_commands_that_need_parallelism&lt;/span&gt;&lt;span class="err"&gt;()&lt;/span&gt;
    &lt;span class="nx"&gt;arguments&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"-parallelism=2"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;extra_arguments&lt;/span&gt; &lt;span class="s2"&gt;"common_tfvars"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;commands&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;get_terraform_commands_that_need_vars&lt;/span&gt;&lt;span class="err"&gt;()&lt;/span&gt;

    &lt;span class="nx"&gt;required_var_files&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="s2"&gt;"${get_parent_terragrunt_dir()}/tfvars/common.tfvars"&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The change in my tutorial repo can be found &lt;a href="https://github.com/paddymorgan84/terragrunt-tutorial/commit/ae3c882673b9faa979ddeac0474a00e85c202a68"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Before and After Hooks
&lt;/h2&gt;

&lt;p&gt;Terragrunt gives you the ability to run commands before and after the execution of a Terraform command. For example, you may run a script to bootstrap your environment or clean up after an &lt;code&gt;apply&lt;/code&gt; has been run. You may want to copy files to certain locations, or even just add extra information that can be outputted as part of the terragrunt commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;  &lt;span class="nx"&gt;before_hook&lt;/span&gt; &lt;span class="s2"&gt;"before_hook"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;commands&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"apply"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nx"&gt;execute&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"echo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Applying my terraform"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;after_hook&lt;/span&gt; &lt;span class="s2"&gt;"after_hook"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;commands&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"apply"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nx"&gt;execute&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"echo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Finished applying Terraform successfully!"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nx"&gt;run_on_error&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Commit &lt;a href="https://github.com/paddymorgan84/terragrunt-tutorial/commit/c30c21ed81bf9c1e4df46ba14a9d8445e34996df"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Auto-init
&lt;/h2&gt;

&lt;p&gt;Something that people will have had to do countless times when running Terraform is running &lt;code&gt;terraform init&lt;/code&gt; before running any other Terraform command. Running this command initialises your working directory by installing provider plugins and initialising your backend configuration. A feature of Terragrunt is that you don't need to explicitly call &lt;code&gt;init&lt;/code&gt;, it will do this automatically before any other commands being run.&lt;/p&gt;

&lt;p&gt;Generally auto-init works fine, but I have found occasions where it hasn't worked as expected. If you want to be totally sure that your modules are initialised before you apply/destroy/plan, you can add in your own before_hook to cover off the scenario.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;terraform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;before_hook&lt;/span&gt; &lt;span class="s2"&gt;"auto_init"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;commands&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"validate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"plan"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"apply"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"destroy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"workspace"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"output"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"import"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nx"&gt;execute&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"terraform"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"init"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The change in my tutorial repo can be found &lt;a href="https://github.com/paddymorgan84/terragrunt-tutorial/commit/150d0b00227d08d012e93a73479dc5e5b54c4481"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  CLI options
&lt;/h2&gt;

&lt;p&gt;Outside of the commands we've been using with Terragrunt, much of which mirrors the commands you would see with Terraform, there are a few particularly useful CLI options to use with Terragrunt as well. This list isn't exhaustive (you can find that &lt;a href="https://terragrunt.gruntwork.io/docs/reference/cli-options/#cli-options"&gt;here&lt;/a&gt;), it's just a list of commands I have found useful in the past:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terragrunt run-all apply &lt;span class="nt"&gt;--terragrunt-non-interactive&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will stop interactive prompts from being displayed, and will prompt all answers with a "yes". Particularly useful when running in CI/CD environments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terragrunt run-all apply &lt;span class="nt"&gt;--terragrunt-working-dir&lt;/span&gt; registry
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can pass directories to Terragrunt to indicate where the Terraform command should run. Note that for any &lt;code&gt;*-all&lt;/code&gt; commands, it will start from that directory but run any subsequent sub-folders with a &lt;code&gt;terragrunt.hcl&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terragrunt run-all apply &lt;span class="nt"&gt;--terragrunt-exclude-dir&lt;/span&gt; registry
terragrunt run-all apply &lt;span class="nt"&gt;--terragrunt-include-dir&lt;/span&gt; registry
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The commands allow you to explicitly exclude and include certain modules (and their dependencies).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terragrunt run-all apply &lt;span class="nt"&gt;--terragrunt-parallelism&lt;/span&gt; 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When passed in, limit the number of modules that are run concurrently to this number during &lt;code&gt;*-all&lt;/code&gt; commands. Note that this parallelism is markedly different from the one you specify using Terraform directly. With Terraform, parallelism indicates running &lt;em&gt;resource&lt;/em&gt; creation concurrently. With Terragrunt, it indicates running entire modules concurrently.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terragrunt run-all apply &lt;span class="nt"&gt;--terragrunt-log-level&lt;/span&gt; trace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want some more detail in your output, you can modify the log levels to do so.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Terragrunt is a fantastic foil for Terraform, taking you the extra yards to make your experience of using Terraform that much better. I've worked on a few projects using Terraform, and my advice would be to leave Terragrunt to the side, at least initially. It's important to understand the problems you're trying to solve, and when they start to manifest for you, that's the time to pull the trigger.&lt;/p&gt;

&lt;p&gt;I've found that the value of Terragrunt increases exponentially with the size of your project. Smaller ones can generally be managed easily with "raw" Terraform, whereas larger, multi-module projects start to really benefit from Terragrunts features.&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://learn.hashicorp.com/collections/terraform/azure-get-started"&gt;Getting started with Terraform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://terragrunt.gruntwork.io/docs/#getting-started"&gt;Getting started with Terragrunt&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://terragrunt.gruntwork.io/docs/features"&gt;All of Terragrunts features&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Credit
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://unsplash.com/@goran_ivos"&gt;Goran Ivos&lt;/a&gt; for the photo 📷&lt;/p&gt;

</description>
      <category>terragrunt</category>
      <category>terraform</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>WSL 2 and terminals</title>
      <dc:creator>Paddy Morgan</dc:creator>
      <pubDate>Fri, 16 Apr 2021 08:41:13 +0000</pubDate>
      <link>https://forem.com/paddymorgan84/wsl-2-and-terminals-28d7</link>
      <guid>https://forem.com/paddymorgan84/wsl-2-and-terminals-28d7</guid>
      <description>&lt;p&gt;My &lt;a href="https://dev.to/paddymorgan84/wsl-2-and-docker-329f"&gt;previous post&lt;/a&gt; focussed on configuring Docker Desktop so that you could integrate seamlessly with WSL 2.&lt;/p&gt;

&lt;p&gt;In this post, I wanted to talk about setting up a standalone terminal for WSL 2. Over the time I've used WSL I've worked with a couple myself and wanted to tell you about my experiences with them, as well as how I configured them for WSL 2.&lt;/p&gt;




&lt;h2&gt;
  
  
  VS Code integrated terminal
&lt;/h2&gt;

&lt;p&gt;I predominantly operate within VS Code as part of any work and personal projects I'm doing. The natural choice when it came to using a terminal was to use the one integrated into VS Code.&lt;/p&gt;

&lt;p&gt;The experience with WSL is seamless. Once you've opened your project in WSL, you can open the terminal pane with &lt;code&gt;ctrl + '&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0a7ftqzmv5otor0mdltd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0a7ftqzmv5otor0mdltd.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to open additional terminals, you can do so with &lt;code&gt;ctrl + shift + '&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh0z9vxdsu859azsrhiy9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh0z9vxdsu859azsrhiy9.png" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I personally find the size of the terminal restrictive. I've tried to mitigate this to an extent by adding a few of my own key bindings to make the most out of the somewhat limited space:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ctrl + up&lt;/code&gt; - Resize the terminal pane to make it larger&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ctrl + down&lt;/code&gt; - Resize the terminal pane to make it smaller&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ctrl + s&lt;/code&gt; - Split existing terminal&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ctrl + x&lt;/code&gt; - Toggle terminal pane being maximised&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ctrl + shift + t&lt;/code&gt; - Switch focus from terminal pane to editor (and vice versa)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can set your own key bindings up by using &lt;code&gt;ctrl + k ctrl + s&lt;/code&gt;, this will bring up the keybindings page. You'll notice that some of the bindings I use are fairly common and likely taken by other commands, &lt;code&gt;ctrl + s&lt;/code&gt; for example. One nice feature with VS Code is that you can add conditional factors for when a keybinding will trigger. &lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;ctrl + s&lt;/code&gt; as an example, it's actually used on 3 occasions, but only triggers on certain conditions that I have specified, making each command unique:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdft7bk285intgxzgu0dq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdft7bk285intgxzgu0dq.png" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You can find the rest of my VS Code key bindings in my &lt;a href="https://github.com/paddymorgan84/dotfiles/blob/master/vscode/keybindings.json" rel="noopener noreferrer"&gt;dotfiles&lt;/a&gt; repo.&lt;/p&gt;

&lt;p&gt;In general, I find the integrated terminal perfectly adequate for what I need. One thing I wish would change, however, is the fact that &lt;a href="https://github.com/Microsoft/vscode/issues/10121" rel="noopener noreferrer"&gt;you can't use VS Code across multiple monitors&lt;/a&gt;. I have a dual-screen setup, and after coming from the world of Visual Studio, it felt very natural for me to use one screen for my code, and the second screen for other purposes; such as debugging, terminals, problems and any other outputs I want to display.&lt;/p&gt;

&lt;p&gt;As a result, I started looking into using a standalone terminal for times when the VS Code integrated terminal isn't quite enough.&lt;/p&gt;




&lt;h2&gt;
  
  
  Hyper
&lt;/h2&gt;

&lt;p&gt;One recommendation I received was &lt;a href="https://hyper.is/" rel="noopener noreferrer"&gt;Hyper.js&lt;/a&gt;. Hyper is an open-source terminal built using &lt;a href="https://www.electronjs.org/" rel="noopener noreferrer"&gt;Electron&lt;/a&gt;. This immediately appealed to me; I find myself crossing OS boundaries more and more often, so having a consistent terminal across them all would be ideal.&lt;/p&gt;

&lt;p&gt;Much like VS Code, it offered a &lt;a href="https://github.com/bnb/awesome-hyper" rel="noopener noreferrer"&gt;wide range of extensions to enhance your experience&lt;/a&gt;. Adding plugins in itself is straightforward; with Hyper open, just press &lt;code&gt;ctrl + ,&lt;/code&gt; and the &lt;code&gt;hyper.js&lt;/code&gt; config will appear. You just need to add the plugin names and Hyper will load them for you:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

  &lt;span class="nx"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
     &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hyper-dracula&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hyper-tabs-enhanced&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hyper-spotify&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hyper-blink&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
     &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hyper-tab-icons&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
     &lt;span class="c1"&gt;//"hyper-solarized-dark"&lt;/span&gt;
     &lt;span class="c1"&gt;//"hyper-material-theme"&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can set up integration with WSL with a couple of changes in your &lt;code&gt;hyper.js&lt;/code&gt; file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

    &lt;span class="nx"&gt;shell&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;C:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;Windows&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;System32&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;wsl.exe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;shellArgs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;~&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;-d&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ubuntu-18.04&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I'm specifying the &lt;code&gt;-d&lt;/code&gt; flag in the &lt;code&gt;shellArgs&lt;/code&gt; to determine the distro I want to open, which in this case is &lt;code&gt;Ubuntu-18.04&lt;/code&gt;. I've also included &lt;code&gt;~&lt;/code&gt; as an additional argument so that the shell opens in my WSL home directory. Without it, Hyper will default to your Windows &lt;code&gt;%userprofile%&lt;/code&gt; directory. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foy4x9a4swzfq4eg6e4t8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foy4x9a4swzfq4eg6e4t8.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see my full configuration file in my &lt;a href="https://github.com/paddymorgan84/dotfiles/blob/master/hyper/.hyper.js" rel="noopener noreferrer"&gt;dotfiles&lt;/a&gt; repo.&lt;/p&gt;

&lt;p&gt;Although I was initially quite excited with what Hyper had to offer, it didn't take me long to become frustrated with it. It has a wide array of plugins, but I found that a lot of them just didn't work with Windows, leaving me with a rather limited terminal experience. It also &lt;a href="https://github.com/vercel/hyper/issues/1147" rel="noopener noreferrer"&gt;restricts you to configuring just one shell&lt;/a&gt;, something I wanted to avoid as I often switch between WSL and Powershell.&lt;/p&gt;




&lt;h2&gt;
  
  
  Windows Terminal
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/microsoft/terminal" rel="noopener noreferrer"&gt;Windows Terminal&lt;/a&gt; is a relatively new terminal application developed by Microsoft. Not only does it support built-in tabs, but it also allows you to configure separate profiles where you can customise a variety of different shells:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0y2k8dmjy3omjvgq7sx9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0y2k8dmjy3omjvgq7sx9.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Better yet, I can split my terminal vertically (&lt;code&gt;Alt + Shift + +&lt;/code&gt;) or horizontally (&lt;code&gt;Alt + Shift + -&lt;/code&gt;) to view them both at once:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjy79722q1osogcpil0iv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjy79722q1osogcpil0iv.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From an aesthetics point of view, Windows Terminal is heavily customisable as well. You can change the colour scheme, change background opacity, and if, like me, you're a fan of using programming ligature through fonts like &lt;a href="https://github.com/tonsky/FiraCode" rel="noopener noreferrer"&gt;Fira Code&lt;/a&gt;, there's support for that too. You can even configure background images for each profile:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqg5sjim6fcphkz4zfzn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqg5sjim6fcphkz4zfzn.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Getting configured with WSL is pretty easy too. Here's the profile I have configured in the settings, which you can open with &lt;code&gt;ctrl + ,&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"guid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"hidden"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Ubuntu-18.04"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"fontFace"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Fira Code"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"source"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Windows.Terminal.Wsl"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"startingDirectory"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\\\\&lt;/span&gt;&lt;span class="s2"&gt;wsl$&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;Ubuntu-18.04&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;home&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;paddy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"colorScheme"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Dracula"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can see my full configuration file in my &lt;a href="https://github.com/paddymorgan84/dotfiles/blob/master/windows-terminal/settings.json" rel="noopener noreferrer"&gt;dotfiles&lt;/a&gt; repo.&lt;/p&gt;

&lt;p&gt;If you want to go an extra step with Windows Terminal there's a very nice &lt;a href="https://marketplace.visualstudio.com/items?itemName=Tyriar.windows-terminal" rel="noopener noreferrer"&gt;extension&lt;/a&gt; you can install for VS Code. The extension gives you the ability to open Windows Terminal from VS Codes context menu, but I've extended my &lt;a href="https://github.com/paddymorgan84/dotfiles/blob/ace3a9572fb56d89d07f061c54cf93fcea7e0235/vscode/keybindings.json#L65" rel="noopener noreferrer"&gt;keybindings&lt;/a&gt; to speed the process up a little. This way I just need a couple of keystrokes and I have a maximised Windows Terminal available on my other monitor.&lt;/p&gt;




&lt;h2&gt;
  
  
  That's a wrap
&lt;/h2&gt;

&lt;p&gt;That's part 4 of my &lt;strong&gt;WSL while you work&lt;/strong&gt; series finished, I hope you found it useful 👍&lt;/p&gt;

&lt;p&gt;Choosing and configuring your terminal is a very personal process, so this post acts as more of a guide to my experiences, as well as some help with integrating them with WSL 2. &lt;/p&gt;

&lt;p&gt;For me, using a combination of VS Codes offering in tandem with Windows Terminal is working really well, and I'm enjoying personalising both tools over time to make myself more productive in my day-to-day working life.&lt;/p&gt;

&lt;p&gt;Next up, I'll be discussing configuring global level settings for WSL using &lt;code&gt;.wslconfig&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Credit
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://unsplash.com/@prateekkatyal" rel="noopener noreferrer"&gt;Prateek Katyal&lt;/a&gt; for the photo 📷&lt;/p&gt;

</description>
      <category>wsl</category>
      <category>terminals</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>WSL 2 and Docker</title>
      <dc:creator>Paddy Morgan</dc:creator>
      <pubDate>Fri, 09 Apr 2021 08:24:42 +0000</pubDate>
      <link>https://forem.com/paddymorgan84/wsl-2-and-docker-329f</link>
      <guid>https://forem.com/paddymorgan84/wsl-2-and-docker-329f</guid>
      <description>&lt;p&gt;My &lt;a href="https://dev.to/paddymorgan84/wsl-2-and-vs-code-3jnf"&gt;previous post&lt;/a&gt; focussed on getting WSL 2 integrated with VS Code, so at this point, you should have a fully-fledged WSL 2 distro that plays nicely with VS Code.&lt;/p&gt;

&lt;p&gt;The next step is to get WSL 2 working with &lt;a href="https://www.docker.com/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Docker (and why it's great)
&lt;/h2&gt;

&lt;p&gt;Docker, in a nutshell, is a tool for deploying and managing containers. &lt;a href="https://docs.docker.com/get-started/#what-is-a-container" rel="noopener noreferrer"&gt;Containers&lt;/a&gt; are loosely isolated environments that allow you to package your application into a standardised "unit". They allow you to abstract away your application from the environment you're running them on. You create containers from an &lt;a href="https://docs.docker.com/get-started/#what-is-a-container-image" rel="noopener noreferrer"&gt;image&lt;/a&gt;, which in turn is created through a set of steps defined through a &lt;a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/" rel="noopener noreferrer"&gt;Dockerfile&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I've been using Docker increasingly over the last couple of years, and the more I use it, the more uses I find for it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I've worked with Docker as part of projects; providing consistent, repeatable and scalable environments for use by others. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I've used it to run tooling; meaning that I don't have to clutter my machine with a multitude of packages as I jump between projects, I can simply pull an image, run it, and trash it once I'm done. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;More recently, I've started to use it as a fully functioning development environment, thanks in no small part to the &lt;a href="https://code.visualstudio.com/docs/remote/containers" rel="noopener noreferrer"&gt;VS Code Remote Container extension&lt;/a&gt;. &lt;a class="mentioned-user" href="https://dev.to/benmatselby"&gt;@benmatselby&lt;/a&gt; has written a great tutorial on getting up and running with VS Code dev containers, I'd wholeheartedly recommend that you &lt;a href="https://dev.to/benmatselby/setting-up-a-vs-code-dev-container-5fjk"&gt;give it a read&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Installing Docker Desktop for Windows
&lt;/h2&gt;

&lt;p&gt;First things first, you're going to need to install &lt;a href="https://hub.docker.com/editions/community/docker-ce-desktop-windows/" rel="noopener noreferrer"&gt;Docker Desktop Stable 2.3.0.2&lt;/a&gt; or later. Docker Desktop is the application that will allow us to build and run our containers on both Windows and WSL.&lt;/p&gt;

&lt;p&gt;During the installation, you'll be prompted to enable any Windows components necessary for WSL 2. You want to do this.&lt;/p&gt;

&lt;p&gt;Provided you've followed the steps from my &lt;a href="https://dev.to/paddymorgan84/getting-started-with-wsl-2-ja"&gt;first post&lt;/a&gt; in the series, you should be ready to go with Docker Desktop 🐳&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd8h7hud5kg4xbssapf81.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd8h7hud5kg4xbssapf81.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Configuring Docker Desktop for WSL 2
&lt;/h2&gt;

&lt;p&gt;Now we've got Docker Desktop installed, there's a two-step checklist we'll need to run through to integrate with WSL 2.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Enable the WSL 2 based engine&lt;/p&gt;

&lt;p&gt;Theoretically, this option should be enabled by default; Docker Desktop will recognise the fact that you have WSL 2 enabled and assume that you want this feature switched on, which you do. It's always good to confirm these things though, so open up Docker Desktop, then select &lt;code&gt;Settings -&amp;gt; General&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F04jsi0ejeg0a11fadl31.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F04jsi0ejeg0a11fadl31.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If for whatever reason you did need to enable the WSL 2 engine, be sure to "Apply &amp;amp; Restart" Docker Desktop.&lt;/p&gt;

&lt;p&gt;If we have a little peek under the hood at what's happened here, you'll notice that we now have a couple of extra WSL distros.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-l&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-v&lt;/span&gt;&lt;span class="w"&gt;

  &lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="w"&gt;                   &lt;/span&gt;&lt;span class="nx"&gt;STATE&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="nx"&gt;VERSION&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Ubuntu-18.04&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;docker-desktop-data&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;docker-desktop&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are installed by Docker Desktop when you enabled the WSL 2 engine. At the risk of horribly exposing my lack of knowledge around the architecture of Docker Desktops WSL 2 backend, I'll keep this short and sweet:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;docker-desktop&lt;/code&gt; replaces the Hyper-V VM implementation Docker Desktop previously used. This handles bootstrapping and management of containers.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;docker-desktop-data&lt;/code&gt; is where your images and configuration are stored; this is essentially a direct replacement of the Virtual Hard Disk that was used previously by Hyper-V.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is great for a couple of reasons. Firstly, it solves the odd restriction Microsoft placed on Windows Home users, for whom Hyper-V (and by extension, Docker) is not available. Although as &lt;a href="https://www.youtube.com/watch?v=dMjQ3hA9mEA" rel="noopener noreferrer"&gt;Jeff&lt;/a&gt; says, &lt;a href="https://www.itechtics.com/enable-hyper-v-windows-10-home/" rel="noopener noreferrer"&gt;life finds a way&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Secondly, because your WSL distros get &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/wsl-config#wsl-2-settings" rel="noopener noreferrer"&gt;full access to all of your CPU cores and 80% of your RAM&lt;/a&gt;, resource allocation is far more dynamic, which on the whole helps to improve a Windows users' Docker experience. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Enable WSL integration for your distro&lt;/p&gt;

&lt;p&gt;Now we have the WSL 2 Engine running, we need to make sure our distro has access to the Docker server running in &lt;code&gt;docker-desktop&lt;/code&gt;. Open up Docker Desktop, then select &lt;code&gt;Settings -&amp;gt; Resources -&amp;gt; WSL Integration&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpsntbu0jf107xs6etgua.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpsntbu0jf107xs6etgua.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any WSL 2 distro will appear in this list. Select whatever distros you'd like to have access to Docker, then select "Apply &amp;amp; Restart".&lt;/p&gt;




&lt;h2&gt;
  
  
  Kicking the tyres
&lt;/h2&gt;

&lt;p&gt;All that's left to do now is give Docker a go in our WSL 2 distro of choice:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0wk5ixjcde7lulhuouby.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0wk5ixjcde7lulhuouby.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Bonus Content: Docker with WSL 1
&lt;/h2&gt;

&lt;p&gt;Although I'm a &lt;a href="https://dev.to/paddymorgan84/getting-started-with-wsl-2-ja"&gt;strong advocate of using WSL 2&lt;/a&gt;, there may be reasons why this is either unavailable or impractical for you.&lt;/p&gt;

&lt;p&gt;There's a little more legwork involved (and a lot less documentation) in getting WSL 1 working with Docker, so here's a quick guide on how I got this working before I migrated to WSL 2:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Install Docker Desktop&lt;/p&gt;

&lt;p&gt;If you don't already have it, you're going to need to install &lt;a href="https://docs.docker.com/docker-for-windows/install/" rel="noopener noreferrer"&gt;Docker Desktop for Windows&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Expose the Docker daemon on Docker Desktop&lt;/p&gt;

&lt;p&gt;Docker Desktop has an option that allows you to open a port to expose the Docker daemon to other clients. You're going to need to have this setting selected:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4wvn5ppxdju3qxs59o1t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4wvn5ppxdju3qxs59o1t.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Install the Docker CLI on WSL 1&lt;/p&gt;

&lt;p&gt;Follow the &lt;a href="https://docs.docker.com/engine/install/ubuntu/" rel="noopener noreferrer"&gt;instructions for installing Docker on Ubuntu&lt;/a&gt;, right up until you get to this point:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;docker-ce docker-ce-cli containerd.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You need only install &lt;code&gt;docker-ce-cli&lt;/code&gt;, as you're going to connect to the exposed port on your Windows machine to access the Docker daemon.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;docker-ce-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Update &lt;code&gt;DOCKER_HOST&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The Docker CLI has a &lt;a href="https://docs.docker.com/engine/reference/commandline/cli/#environment-variables" rel="noopener noreferrer"&gt;list of environment variables&lt;/a&gt; that it looks for when it runs. One of these is &lt;code&gt;DOCKER_HOST&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;We want to update &lt;code&gt;DOCKER_HOST&lt;/code&gt; in WSL so that the Docker CLI knows that we want to connect to the exposed Docker daemon on your Windows machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export DOCKER_HOST=tcp://localhost:2375
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to make this change a little more permanent, you can add it to a shell config file of your choosing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "export DOCKER_HOST=tcp://localhost:2375" &amp;gt;&amp;gt; ~/.zshrc &amp;amp;&amp;amp; . ~/.zshrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With those 4 steps complete, you'll be able to run Docker commands from WSL 1.&lt;/p&gt;




&lt;h2&gt;
  
  
  That's a wrap
&lt;/h2&gt;

&lt;p&gt;Part 3 of the series is complete! The next item I'll discuss is using a standalone terminal with WSL 2, and how to configure it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/get-started/overview/" rel="noopener noreferrer"&gt;Getting started with Docker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/docker-for-windows/" rel="noopener noreferrer"&gt;Docker Desktop - User Manual&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/docker-for-windows/install/" rel="noopener noreferrer"&gt;Installing Docker Desktop on Windows&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.docker.com/blog/new-docker-desktop-wsl2-backend/" rel="noopener noreferrer"&gt;Docker Desktop - WSL 2 Backend Architecture&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Credit
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://unsplash.com/@jexo" rel="noopener noreferrer"&gt;Jexo&lt;/a&gt; for the photo 📷&lt;/p&gt;

</description>
      <category>wsl</category>
      <category>docker</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>WSL 2 and VS Code</title>
      <dc:creator>Paddy Morgan</dc:creator>
      <pubDate>Thu, 01 Apr 2021 08:39:57 +0000</pubDate>
      <link>https://forem.com/paddymorgan84/wsl-2-and-vs-code-3jnf</link>
      <guid>https://forem.com/paddymorgan84/wsl-2-and-vs-code-3jnf</guid>
      <description>&lt;p&gt;My &lt;a href="https://dev.to/paddymorgan84/getting-started-with-wsl-2-ja"&gt;first post&lt;/a&gt; in the series focussed primarily on installing WSL 2 and getting familiar with some of its standard features and commands. Hopefully, at this point, you'll have a fully functioning distro running on your machine. If not, have a read back and get yourself up and running.&lt;/p&gt;

&lt;p&gt;With the second post, I want to focus more on how you can start to make use of WSL 2 as part of your day to day engineering life.  &lt;/p&gt;




&lt;h2&gt;
  
  
  Working with VS Code
&lt;/h2&gt;

&lt;p&gt;I primarily use &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt; as my IDE. It's open-source, lightweight &amp;amp; clean, has a very active community with regular updates, and it has a vast array of extensions available to you, one of which is the &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl" rel="noopener noreferrer"&gt;Remote WSL extension&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While your IDE remains on Windows, all your commands, extensions, files, and terminal are running on your WSL instance. Once you've installed the extension you'll see a little icon at the bottom left of VS Code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvqyaen0fjfpexvphgqxm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvqyaen0fjfpexvphgqxm.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Opening a project
&lt;/h2&gt;

&lt;p&gt;To better show this, I'm going to clone one of my repos into WSL. When I clone git repos, I like to have a &lt;code&gt;git&lt;/code&gt; folder in the &lt;code&gt;$HOME&lt;/code&gt; directory, followed by the organisation or user within that. So for example, on a fresh WSL distro install, I would do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; ~ 
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; git/paddymorgan84
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;git/paddymorgan84
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; git clone https://github.com/paddymorgan84/dotfiles.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;Sidenote&lt;/strong&gt;: The &lt;code&gt;-p&lt;/code&gt; flag we're using for &lt;code&gt;mkdir&lt;/code&gt; indicates that if the parent directory doesn't exist (which in this case, it definitely won't) rather than error it will create that directory as well, concatenating your &lt;code&gt;mkdir&lt;/code&gt; command into a single call.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There's a couple of ways you can open a project:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 1: From VS Code&lt;/strong&gt;. You can use &lt;code&gt;ctrl + shift + p&lt;/code&gt; to open up your command palette, then search for &lt;code&gt;WSL&lt;/code&gt;, which will provide you with a multitude of WSL related options. Clicking on the new icon in the bottom left of VS Code will also present you with the same options:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkid9q5akja4ktxdbyeuv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkid9q5akja4ktxdbyeuv.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select &lt;code&gt;Remote-WSL: Open folder in WSL...&lt;/code&gt; and it will open up Windows Explorer and point you to a network drive that's been created on your machine to support WSL:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr6664h7pnbjorpfv45rg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr6664h7pnbjorpfv45rg.png" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;This gives you the ability to browse your WSL distro in the same way you would a Windows filesystem to locate your project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F06w5ywl53e0vf11rs5pc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F06w5ywl53e0vf11rs5pc.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you've selected your folder, VS Code will open up your project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2fikju6ayg5deboh8tj4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2fikju6ayg5deboh8tj4.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two things to take note of here. The first is that the bottom left of your IDE will indicate you're now using a remote WSL connection to your Ubuntu-18.04 distro. The second is that your integrated terminal (&lt;code&gt;ctrl + '&lt;/code&gt; if you don't see this) is also using your distro, and will have automatically opened to the location of your project on your WSL filesystem. This gives you a clean, immersive experience of developing within Linux.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 2: From WSL&lt;/strong&gt;. If you want to work directly from the terminal (as I tend to do) then you can call the &lt;code&gt;code&lt;/code&gt; command from your distro, which will open a VS Code instance on your Windows machine with whatever folder you've run the code command for. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;git/paddymorgan84/dotfiles
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; code &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or alternatively...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; code ~/git/paddymorgan84/dotfiles
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Personally, I'm a big fan of using the terminal and I try to operate out of there as much as possible. I feel it's more efficient and makes me more productive as an engineer, and it also means I can add cool little aliases that can open my common projects up with a few keystrokes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2o6plwbzbn4m8831fvxx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2o6plwbzbn4m8831fvxx.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'll be discussing aliases later in the series.&lt;/p&gt;




&lt;h2&gt;
  
  
  Installing extensions
&lt;/h2&gt;

&lt;p&gt;Using the Remote WSL extension means that instead of having a totally native experience, what you actually have is a "client-server" architecture; VS Code (the UI, at least) is running on Windows, but the server (everything else under the hood) is running remotely on WSL.&lt;/p&gt;

&lt;p&gt;As a result, a lot of your extensions will need to be re-installed on your distro (and any subsequent distro) for you to have them available. &lt;/p&gt;

&lt;p&gt;Fortunately, VS Code makes this really easy. Assuming you have a WSL remote project open, press &lt;code&gt;ctrl + shift + x&lt;/code&gt; to present you with the Extensions pane. You'll notice a few subtle differences from a standard Windows VS Code experience (I've highlighted the important bits):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxh0xmhfymiz1chyn8xew.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxh0xmhfymiz1chyn8xew.png" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Local - Installed&lt;/code&gt; tells you what extensions you have installed when running VS Code with a Windows-based project.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;WSL:Ubuntu-18.04 - Installed&lt;/code&gt; tells you what extensions you have installed on your distro.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Install in WSL:Ubuntu-18.04&lt;/code&gt; does what it says on the tin. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The thing I want to emphasise about this is that getting all the extensions you love to use on Windows can be installed onto your distro in a matter of seconds 👍&lt;/p&gt;




&lt;h2&gt;
  
  
  Don't halfway-house the filesystem
&lt;/h2&gt;

&lt;p&gt;When I first started dabbling with WSL, I rather confusingly decided to keep my files located on my Windows drive, then use the mount points WSL provide (&lt;code&gt;/mnt/c/&lt;/code&gt;, for example) to locate those files and operate from WSL.&lt;/p&gt;

&lt;p&gt;As I write this now, I struggle to remember why I did this other than the fact it wasn't quite as big a leap away from Windows and there was less up-front work to get started. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I would wholeheartedly recommend you don't do this.&lt;/strong&gt; Firstly, Microsoft themselves &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/compare-versions#performance-across-os-file-systems" rel="noopener noreferrer"&gt;try to warn you against this&lt;/a&gt;, primarily because the performance isn't great. &lt;/p&gt;

&lt;p&gt;Secondly, I found that I would have annoying inconsistencies that meant I had to modify my configuration to work around it. For example, I often found myself battling with line endings in my GitHub repos, something that differs between Windows and Linux. &lt;a href="https://docs.github.com/en/github/getting-started-with-github/configuring-git-to-handle-line-endings" rel="noopener noreferrer"&gt;Git has ways and means to help solve this&lt;/a&gt;, but ultimately I migrated all of my projects to my distro and my experience improved drastically. &lt;/p&gt;

&lt;p&gt;My advice would be to just take the leap.&lt;/p&gt;




&lt;h2&gt;
  
  
  That's a wrap
&lt;/h2&gt;

&lt;p&gt;Part 2 of my series is done and dusted, I really hope that you've found it useful. Next up I'll be talking about using WSL 2 with Docker. 🐳&lt;/p&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;Installing VS Code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.microsoft.com/en-us/windows/wsl/tutorials/wsl-vscode#open-a-wsl-project-in-visual-studio-code" rel="noopener noreferrer"&gt;Getting started with VS Code &amp;amp; WSL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://code.visualstudio.com/docs/remote/wsl-tutorial" rel="noopener noreferrer"&gt;VS Code &amp;amp; WSL tutorial&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Credit
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://unsplash.com/@axellvak" rel="noopener noreferrer"&gt;Remy_Loz&lt;/a&gt; for the photo 📷&lt;/p&gt;

</description>
      <category>wsl</category>
      <category>vscode</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Getting started with WSL 2</title>
      <dc:creator>Paddy Morgan</dc:creator>
      <pubDate>Fri, 26 Mar 2021 09:21:01 +0000</pubDate>
      <link>https://forem.com/paddymorgan84/getting-started-with-wsl-2-ja</link>
      <guid>https://forem.com/paddymorgan84/getting-started-with-wsl-2-ja</guid>
      <description>&lt;p&gt;My life as an engineer has predominantly been one within the realms of Windows. Whilst some may shudder at the thought, I've always been happy working in this environment. Over the last couple of years, however, I've gradually been exposed to the world of Linux, predominantly through my use of &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/" rel="noopener noreferrer"&gt;WSL&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;This year I've been co-running a weekly technical workshop with &lt;a href="https://github.com/benmatselby" rel="noopener noreferrer"&gt;Ben Selby&lt;/a&gt; on a range of subjects. Last week I ran a workshop on my experiences with WSL, outlining what I've learnt along the way and how I try to get the most out of it.&lt;/p&gt;

&lt;p&gt;This post marks the first of a small series around WSL I'd like to do off the back of that workshop.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is WSL?
&lt;/h2&gt;

&lt;p&gt;WSL, or Windows Subsystem for Linux, is an optional feature on Windows that allows you to install a Linux distribution without any of the previous legwork you would have done previously, such as dual-booting your PC, or setting up a VM.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why WSL 2?
&lt;/h2&gt;

&lt;p&gt;I originally started using WSL 1, and while I could work fairly comfortably with it, the nature of my work meant that I did have a couple of frustrating issues, namely around Docker and the way WSL &lt;a href="https://github.com/docker/for-win/issues/2151" rel="noopener noreferrer"&gt;resolved the mounting of volumes&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;WSL 2 was a major architectural change for WSL, introducing the use of a full Linux Kernel, increased file system performance and 100% system call compatibility. &lt;/p&gt;

&lt;p&gt;In my opinion, WSL 2 is far superior, and if you're new to WSL I'd skip straight past WSL 1. As always, there are &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/compare-versions#exceptions-for-using-wsl-1-rather-than-wsl-2" rel="noopener noreferrer"&gt;exceptions&lt;/a&gt; to bear in mind, but they're unlikely to be an issue for the majority.&lt;/p&gt;




&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;p&gt;I'll get the boring stuff out of the way early. To install WSL 2, you're going to need to be running the following at the very least:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;x64&lt;/strong&gt;: Windows version 1903 or higher, with Build 18362 or higher.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ARM64&lt;/strong&gt;: Windows version 2004 or higher, with Build 19041 or higher.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can use &lt;code&gt;winver&lt;/code&gt; to find this out 👍&lt;/p&gt;




&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Installing WSL is quick and simple; I'm using PowerShell (as admin) for the commands below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt; - Enable WSL and virtual machine features&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;dism.exe&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/online&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/enable-feature&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/featurename:Microsoft-Windows-Subsystem-Linux&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/all&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/norestart&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;dism.exe&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/online&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/enable-feature&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/featurename:VirtualMachinePlatform&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/all&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/norestart&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt; - Download the &lt;a href="https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" rel="noopener noreferrer"&gt;linux kernel package&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt; - Set WSL 2 as your default (more on &lt;code&gt;wsl.exe&lt;/code&gt; later)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--set-default-version&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt; - &lt;a href="https://aka.ms/wslstore" rel="noopener noreferrer"&gt;Choose your distro&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qig5572axkhwjyb0dfp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qig5572axkhwjyb0dfp.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt; - Create your user account and password&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyyni87n84rb0hh7yjvs2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyyni87n84rb0hh7yjvs2.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6&lt;/strong&gt; - Confirm everything is up and running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--list&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-v&lt;/span&gt;&lt;span class="w"&gt;

  &lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="w"&gt;                   &lt;/span&gt;&lt;span class="nx"&gt;STATE&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="nx"&gt;VERSION&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;docker-desktop-data&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Ubuntu-18.04&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;docker-desktop&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Making use of &lt;code&gt;wsl.exe&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;As you may have gathered from the installation instructions, you can interact with WSL by using the &lt;code&gt;wsl&lt;/code&gt; command. &lt;/p&gt;

&lt;p&gt;There are a &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/reference" rel="noopener noreferrer"&gt;few different things&lt;/a&gt; you can do with it, but here are the commands I've found most useful:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Opening the default distro&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--list&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-v&lt;/span&gt;&lt;span class="w"&gt;

    &lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="w"&gt;                   &lt;/span&gt;&lt;span class="nx"&gt;STATE&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="nx"&gt;VERSION&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;docker-desktop-data&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Ubuntu-18.04&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;docker-desktop&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;*&lt;/code&gt; denotes the default distribution. If you enter &lt;code&gt;wsl&lt;/code&gt; it opens the default shell, which in this case is &lt;code&gt;Ubuntu-18.04&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you do have multiple distros and you want to log in to a "non-default", you can add some more context to your command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--list&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-v&lt;/span&gt;&lt;span class="w"&gt;

  &lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="w"&gt;                   &lt;/span&gt;&lt;span class="nx"&gt;STATE&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="nx"&gt;VERSION&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;docker-desktop-data&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Ubuntu-18.04&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;Debian&lt;/span&gt;&lt;span class="w"&gt;                 &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;docker-desktop&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-d&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Debian&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Changing the version of WSL for your distro&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--set-version&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Ubuntu-18.04&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;1&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--list&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-v&lt;/span&gt;&lt;span class="w"&gt;

  &lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="w"&gt;                   &lt;/span&gt;&lt;span class="nx"&gt;STATE&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="nx"&gt;VERSION&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;docker-desktop-data&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Ubuntu-18.04&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;1&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;docker-desktop&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is admittedly an odd example given my belief that most engineers will be best served by using WSL 2, but it's useful nonetheless. You can switch between versions with a single command, which can be handy if for whatever reason you have a version-specific issue you need a workaround for. For now, at least, &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/wsl2-faq#what-will-happen-to-wsl-1--will-it-be-abandoned-" rel="noopener noreferrer"&gt;Microsoft has no plans to deprecate WSL 1&lt;/a&gt;, so it's worth having this in your locker.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Importing and exporting distros&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--export&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Ubuntu-18.04&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;C:\wsl-exports\ubuntu.tar&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Ubunthree-18.04&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;C:\my-distros\ubunthree&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;C:\wsl-exports\ubuntu.tar&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--list&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-v&lt;/span&gt;&lt;span class="w"&gt;

  &lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="w"&gt;                   &lt;/span&gt;&lt;span class="nx"&gt;STATE&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="nx"&gt;VERSION&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;docker-desktop-data&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Ubuntu-18.04&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;docker-desktop&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;Ubunthree-18.04&lt;/span&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nx"&gt;Running&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="nx"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you install your distro of choice from the Microsoft Store you can't subsequently get that same distro again as it's now considered installed. &lt;/p&gt;

&lt;p&gt;You can, however, export your existing distro to a &lt;code&gt;.tar&lt;/code&gt; file, then import it again under a different name, as the example above shows. I found this very useful when I was comparing the features of WSL 1 &amp;amp; 2, but you could do it for a multitude of other reasons, such as splitting your personal or work projects across distros or splitting by technical disciplines, such as front or backend development.&lt;/p&gt;

&lt;p&gt;If you work with a team of engineers, it can also be useful to have a tarball of a "base" distro that has everything your team needs pre-baked into the distro.&lt;/p&gt;




&lt;h2&gt;
  
  
  The snagging list
&lt;/h2&gt;

&lt;p&gt;As great as WSL 2 is, there's a couple of hiccups that I've found along the way that I want to share in the hope that others avoid the hair pulling and excessive profanity I engaged in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Symantec Endpoint Protection played &lt;a href="https://github.com/microsoft/WSL/issues/4926#issuecomment-590829828" rel="noopener noreferrer"&gt;havoc&lt;/a&gt; with my ability to perform apt package-management updates and upgrades. Fortunately, I don't use Symantec anymore and I'm not sure if they've patched out a fix to resolve it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Recently I came across an issue with my distro whereby I couldn't hit the internet at all. I was stumped, but thankfully &lt;a href="https://github.com/coltenkrauter" rel="noopener noreferrer"&gt;@coltenkrauter&lt;/a&gt; created a &lt;a href="https://gist.github.com/coltenkrauter/608cfe02319ce60facd76373249b8ca6#file-fix-wsl2-dns-resolution" rel="noopener noreferrer"&gt;gist&lt;/a&gt; that gave step by step instructions on how to solve it. ❤️&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The ability to convert your distro between WSL 1 &amp;amp; WSL 2 can be really useful but be warned that the larger it gets, the longer the conversion times will get. Conversion on a fresh distro is a matter of seconds, but when I've been using a distro for a protracted amount of time (I'm talking months here) with large numbers of cloned repos, you're going to be looking at hours.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  That's a wrap
&lt;/h2&gt;

&lt;p&gt;This marks the end of part 1 of my &lt;strong&gt;WSL while you work&lt;/strong&gt; series. Next up will be a post on how I use VS Code in conjunction with WSL for my day-to-day engineering.&lt;/p&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10" rel="noopener noreferrer"&gt;Installing WSL2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.microsoft.com/en-us/windows/wsl/compare-versions" rel="noopener noreferrer"&gt;WSL 1 vs WSL 2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.microsoft.com/en-us/windows/wsl/reference" rel="noopener noreferrer"&gt;WSL command reference&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Credit
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://unsplash.com/@oskaryil" rel="noopener noreferrer"&gt;Oskar Yildiz&lt;/a&gt; for the photo 📷&lt;/p&gt;

</description>
      <category>wsl</category>
      <category>windows</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
