<?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>DEV Community: jnous-5</title>
    <description>The latest articles on DEV Community by jnous-5 (@jnous5).</description>
    <link>https://dev.to/jnous5</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%2F565820%2Fd4b15d3f-5ad1-4f86-9bda-6a206ca0c67a.png</url>
      <title>DEV Community: jnous-5</title>
      <link>https://dev.to/jnous5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jnous5"/>
    <language>en</language>
    <item>
      <title>Setting-up a local development environment using VS Code, Docker, and WSL 2</title>
      <dc:creator>jnous-5</dc:creator>
      <pubDate>Sun, 07 Feb 2021 10:50:50 +0000</pubDate>
      <link>https://dev.to/jnous5/setting-up-a-local-development-environment-using-vs-code-docker-and-wsl-2-5c0i</link>
      <guid>https://dev.to/jnous5/setting-up-a-local-development-environment-using-vs-code-docker-and-wsl-2-5c0i</guid>
      <description>&lt;p&gt;Developing software within a Windows environment is such a pain especially if you're into writing web applications. In my case, most of the web apps I made are deployed and ran on a Linux machine hosted on the cloud. This means that I can't issue commands on my local machine as I did on the server.&lt;/p&gt;

&lt;p&gt;In this post, I'll share how I achieved setting-up my Windows machine to use WSL 2 alongside Docker and VS Code to create a local development environment that runs on a Linux environment (Ubuntu 20.04 LTS).&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;p&gt;Before you proceed make sure you have already installed the following applications on your machine.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/docker-for-windows/install/" rel="noopener noreferrer"&gt;Docker Desktop on Windows&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.microsoft.com/en-us/windows/terminal/get-started" rel="noopener noreferrer"&gt;Windows Terminal&lt;/a&gt; &lt;em&gt;(Recommended but not required)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://code.visualstudio.com/docs/setup/windows" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
Make sure you have ticked the option to add VS Code to Window's path. We will be needing this to use the &lt;code&gt;code&lt;/code&gt; command within the WSL environment.&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%2Fi%2Fzj17eo7bmpu8klxxd0dy.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%2Fi%2Fzj17eo7bmpu8klxxd0dy.png" alt="VS Code installation instructions"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;After you have installed the required applications, you can now start with the steps as detailed below.&lt;/p&gt;
&lt;h3&gt;
  
  
  Installing Ubuntu on WSL
&lt;/h3&gt;

&lt;p&gt;The environment I choose to develop to is Ubuntu (20.04 LTS) but you can choose any other Linux distros you prefer. Beware though that not all are free.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open up &lt;a href="https://support.microsoft.com/en-us/account-billing/how-to-open-microsoft-store-on-windows-10-e080b85a-7c9e-46a7-8d8b-3e9a42e32de6" rel="noopener noreferrer"&gt;Microsoft Store&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Search and select &lt;a href="https://www.microsoft.com/en-us/p/ubuntu-2004-lts/9n6svws3rx71?activetab=pivot:overviewtab" rel="noopener noreferrer"&gt;Ubuntu 20.04 LTS&lt;/a&gt; (or your preferred Linux distro).&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;GET&lt;/strong&gt; button. This will download and install Ubuntu on your machine.&lt;/li&gt;
&lt;li&gt;Once finished, click &lt;strong&gt;Launch&lt;/strong&gt;. This will open a command prompt and asks you to setup the user account of the system.&lt;/li&gt;
&lt;/ol&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%2Fi%2Fk9jz1slexlmz9p2z2rn2.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%2Fi%2Fk9jz1slexlmz9p2z2rn2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol start="5"&gt;&lt;li&gt;And that's it! You have now installed and ran Ubuntu on your Windows machine.&lt;/li&gt;&lt;/ol&gt;
&lt;h3&gt;
  
  
  Setting-up Ubuntu to use WSL 2
&lt;/h3&gt;

&lt;p&gt;By default, Windows installs your distro using WSL 1 but in this case, we will be using WSL 2. WSL 2 is the newest version and is much faster than WSL 1 in terms of file system performance. For comparison, you can check this link &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/compare-versions" rel="noopener noreferrer"&gt;Comparing WSL 1 and WSL 2&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Verify which version of WSL your distro is using by clicking &lt;strong&gt;Start&lt;/strong&gt;, type &lt;strong&gt;PowerShell&lt;/strong&gt;, and select &lt;strong&gt;Windows PowerShell&lt;/strong&gt;. Copy and run the command below.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;PS&amp;gt; wsl &lt;span class="nt"&gt;-l&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It should show a similar output as below. If the version of your distro is already 2, feel free to skip this section.&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%2Fi%2Fnfl5v4g4bfjkke21393i.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%2Fi%2Fnfl5v4g4bfjkke21393i.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol start="2"&gt;&lt;li&gt;
To convert to version 2, copy and run the command below substituting the placeholders with your actual values. Note that you can always switch back between versions.
&lt;/li&gt;&lt;/ol&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# wsl --set-version &amp;lt;distribution-name&amp;gt; &amp;lt;version-number&amp;gt;&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;wsl &lt;span class="nt"&gt;--set-version&lt;/span&gt; Ubuntu-20.04 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol start="3"&gt;&lt;li&gt;
And that's it! Running the command again from step 1 should now show version 2.
&lt;/li&gt;&lt;/ol&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%2Fi%2F3l5h49t90ap02tipkotk.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%2Fi%2F3l5h49t90ap02tipkotk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Configuring Docker for WSL Integration
&lt;/h3&gt;

&lt;p&gt;Configuring Docker Desktop for WSL 2 is quite easy. We just need to enable a few settings and we're good to go.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start &lt;strong&gt;Docker Desktop&lt;/strong&gt; via Windows &lt;strong&gt;Start&lt;/strong&gt; menu.&lt;/li&gt;
&lt;li&gt;Open &lt;strong&gt;Settings&lt;/strong&gt; by right-clicking Docker icon located in the System tray.
&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%2Fi%2F54p0hixnpdgdkahoovxk.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;General&lt;/strong&gt;, make sure &lt;strong&gt;Use the WSL 2 based engine&lt;/strong&gt; is ticked.
&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%2Fi%2Fwizuqscpuxcav7f5ewfh.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Next, under &lt;strong&gt;Resources &amp;gt; WSL INTEGRATION&lt;/strong&gt;, enable the Linux distro you would like to be integrated with Docker.
&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%2Fi%2Fjgd7u448fcer9kvivk0w.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Hit &lt;strong&gt;Apply &amp;amp; Restart&lt;/strong&gt; button and you're done!&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Installing Windows Terminal
&lt;/h3&gt;

&lt;p&gt;This is an optional step and you're free to skip this section. I highly recommend installing Windows Terminal though as it makes it easy to start and switch between distros (if you have more than one). Plus, compared to CMD, it has a nice UI!&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%2Fi%2F4w1lnnce3qg0n2hklnpj.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%2Fi%2F4w1lnnce3qg0n2hklnpj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Windows Terminal via &lt;a href="https://www.microsoft.com/en-ph/p/windows-terminal/9n0dx20hk701?rtc=1&amp;amp;activetab=pivot:overviewtab" rel="noopener noreferrer"&gt;Microsoft Store&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;GET&lt;/strong&gt; button and it should download and install Windows Terminal.&lt;/li&gt;
&lt;li&gt;To open, simply hit &lt;strong&gt;Start&lt;/strong&gt; and search for &lt;strong&gt;Windows Terminal&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, when we want to connect to an installed Linux distro, we can just easily click the dropdown menu located at the top. In my case, using &lt;strong&gt;Ubuntu-20.04&lt;/strong&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%2Fi%2Fcpcm908uokuc0vqelimj.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%2Fi%2Fcpcm908uokuc0vqelimj.png" alt="Alt Text"&gt;&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%2Fi%2Fdbe4owuqajon2zs3exio.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%2Fi%2Fdbe4owuqajon2zs3exio.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Setting-up VS Code for remote development
&lt;/h3&gt;

&lt;p&gt;We will be using a Docker container as our development environment running in the Ubuntu distro we had previously setup. Inside this container will be our project and its dependencies. But before we can make changes to our code, we need to have VS Code connect to our WSL environment first. To do this, we have to install a VS Code extension called &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack" rel="noopener noreferrer"&gt;Remote Development&lt;/a&gt;. Go ahead and install this extension.&lt;/p&gt;

&lt;p&gt;If you notice, this is an extension pack meaning it will install the following: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh" rel="noopener noreferrer"&gt;Remote - SSH&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl" rel="noopener noreferrer"&gt;Remote - WSL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers" rel="noopener noreferrer"&gt;Remote - Containers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The important ones are the &lt;strong&gt;Remote - WSL&lt;/strong&gt; and &lt;strong&gt;Remote - Containers&lt;/strong&gt; as this will allow us to connect inside WSL and in our Docker container.&lt;/p&gt;

&lt;p&gt;After the installation, you'll notice that a new status bar located at the bottom-left is now available. Clicking this item will give you different options on how you want to open your project.&lt;br&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%2Fi%2Fh7byq4pzp1qzaywd1ma6.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%2Fi%2Fh7byq4pzp1qzaywd1ma6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Creating our sample project
&lt;/h3&gt;

&lt;p&gt;Now that we have installed the extension, VS Code should now be able to open a project inside WSL. Since we don't have a project yet, let's go ahead and create a sample Laravel project.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open &lt;strong&gt;Windows Terminal&lt;/strong&gt; and connect to your installed distro (Ubuntu-20.04).&lt;/li&gt;
&lt;li&gt;Create a Laravel project on your chosen directory.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /opt/workspace/
&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;-s&lt;/span&gt; https://laravel.build/example-app | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol start="3"&gt;&lt;li&gt;
Next, we'll open this project in VS Code. Remember I mentioned that you need to tick the option to add VS Code in Windows Path? The reason is we will be using the &lt;code&gt;code&lt;/code&gt; command to open our project.
&lt;/li&gt;&lt;/ol&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;example-app
&lt;span class="nv"&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;You'll know that you're opening a project inside a WSL if you're seeing this in the status bar.&lt;br&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%2Fi%2F8ubhl9fmejie4b1y1wz5.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%2Fi%2F8ubhl9fmejie4b1y1wz5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TIP:&lt;/strong&gt;&lt;br&gt;
It's pretty amazing that we can invoke a Windows application inside our Ubuntu environment. As a matter of fact, you can actually open File explorer in the current directory by typing &lt;code&gt;explorer.exe .&lt;/code&gt;. Try it!&lt;/p&gt;
&lt;h3&gt;
  
  
  Creating a development container
&lt;/h3&gt;

&lt;p&gt;Now that we have our sample project, we just need to bind this into our Docker container. We will be leveraging VS Code's Remote Containers extension.&lt;/p&gt;

&lt;p&gt;The power of Remote Containers lies in a file called &lt;code&gt;devcontainer.json&lt;/code&gt;. This will instruct how VS Code will access or create our Docker container.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open &lt;strong&gt;Command Palette (F1)&lt;/strong&gt; and search for &lt;strong&gt;Remote-Containers: Add Development Container Configuration Files...&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;From a predefined container configuration...&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;PHP &amp;amp; MariaDB&lt;/strong&gt;. This will create a new folder in your root project directory called &lt;code&gt;.devcontainer&lt;/code&gt; with the following files.
&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%2Fi%2Fw99gjbz1gak0qcisg7sf.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Since we will be using &lt;code&gt;artisan serve&lt;/code&gt;, we must add the port &lt;code&gt;8000&lt;/code&gt; as one of the &lt;code&gt;forwardPorts&lt;/code&gt; values.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"forwardPorts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3306&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8000&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;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;ol&gt;
&lt;li&gt;To build this, hit &lt;strong&gt;F1&lt;/strong&gt; and search &lt;strong&gt;Reopen in Container&lt;/strong&gt;. Note that this might take awhile but will be faster the next time we rebuild.
&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%2Fi%2Fg3vl8flifehbkvt1p480.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Once build, open a new &lt;strong&gt;Terminal&lt;/strong&gt; and start PHP's built-in development server.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;php artisan serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you notice, the opened Terminal automatically connects to the container, giving us little hassle as we no longer need to use &lt;code&gt;Docker exec&lt;/code&gt; commands.&lt;/p&gt;

&lt;ol start="6"&gt;&lt;li&gt;
Got ahead and open up localhost:8000. You should see Laravel's welcome route.
&lt;/li&gt;&lt;/ol&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%2Fi%2Fx4w2bnv5uzegkx9hsjtg.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%2Fi%2Fx4w2bnv5uzegkx9hsjtg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course, we wouldn't want to manually issue the &lt;code&gt;artisan serve&lt;/code&gt; command every time we want to start our project. To automate this, we can use another VS Code feature called &lt;a href="https://code.visualstudio.com/docs/editor/tasks" rel="noopener noreferrer"&gt;Tasks&lt;/a&gt; and configure it to run every time our project folder is opened.&lt;/p&gt;

&lt;p&gt;And that's it! As we saw, we now have a local development environment running on a container under WSL 2 (Ubuntu-20.04). If you want to add other dependencies to our container like git and composer, you just need to modify the &lt;code&gt;.devcontainer/Dockerfile&lt;/code&gt; file and rebuild the project once again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TIP:&lt;/strong&gt;&lt;br&gt;
If you're running low on system memory due to virtualization, we can instruct Windows to only allocate a certain amount of memory for virtualization. To do this, create a file in &lt;code&gt;%userprofile%&lt;/code&gt; called &lt;code&gt;.wslconfig&lt;/code&gt; and paste the content below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[wsl2]
processors=4 # Number of processors to allocate.
memory=4GB   # Maximum amount of memory to allocate.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before this takes effect, you may need to shutdown WSL by running the command below on &lt;strong&gt;Powershell&lt;/strong&gt; and restarting &lt;strong&gt;Docker Desktop&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;PS&amp;gt; wsl &lt;span class="nt"&gt;--shutdown&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this, open your &lt;strong&gt;Task Manager&lt;/strong&gt; and look for &lt;strong&gt;Vmmem&lt;/strong&gt;. The memory consumption should drop around your set values.&lt;br&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%2Fi%2Ff5jgvennc2alf805f28f.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%2Fi%2Ff5jgvennc2alf805f28f.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>vscode</category>
      <category>docker</category>
      <category>windows</category>
    </item>
  </channel>
</rss>
