I ran a Docker container inside Windows Subsystem for Linux!

Madhuresh Gupta
Level Up Coding
Published in
5 min readJun 23, 2020

--

Hello Everyone! This is part 1 of a 2 part tutorial where I teach how to run your first docker container in WSL 2 inside Windows 10.

As a picture can say a thousand words, I have included screenshots for every possible step to make the process crystal clear for everyone.

In this first part, I am going to show you how to get started with running WSL 2 in your Windows device.

WSL (Windows Subsystem for Linux) version 2 is a whole lot different compared to its predecessor WSL 1 where rather than using a translation layer between Linux and Windows, WSL 2 uses a virtualization technology in order to run a lightweight virtual machine directly onto Windows 10.

Gone are the days where Microsoft hated Linux! Microsoft changed dramatically over the last few years, they have purchased GitHub, they have worked a lot in Azure to improve the cloud computing with their aim to become “The world’s computer” and now they give you a Linux kernel with Windows! YES!

This makes anyone with a Windows laptop easy to learn Linux, develop on Linux, etc.

Windows operating system development has a very tight integration for the WSL 2. Okay so let me start explaining the steps to install WSL 2:

  1. Windows 10 Home, version 2004 or higher.

2. Now to go to start menu and search for “Windows features”

3. Go ahead and enable “Virtual Machine Platform” and “Windows Subsystem for Linux” and click OK.

4. The above step will search for the required files and apply the required changes and go ahead and reboot your computer.

5. Now go this website and download the update package and install the WSL update setup.

Now this has successfully installed WSL 2 in your computer.

6. After restarting, set WSL 2 as your default version
For that open PowerShell and type the following :

wsl --set-default-version 2

7. Next up we have to install a Linux Distro, open the Microsoft Store and select your favorite distribution.

I have installed Ubuntu, you can go with anything else whatever you are comfortable with.

8. Now as an additional productivity tool, also download the Windows Terminal from the store.

9. Once the installation is complete, open the Ubuntu from the start menu and it will ask you to create a user and set the password, once done you will receive the following info:

Congratulations you have successfully enabled and installed a Linux distribution inside your Windows computer (take a moment to pat your back!).
10. Now most probably you might be using VS Code for development, if you open this now you will see the below prompt. Go ahead and add the “Remote-WSL” extension.

Okay so now we have enabled WSL 2, installed a Linux distribution and made VS Code ready for your future Linux distribution. Now let me guide you with installing Docker desktop for WSL 2.

  1. First up, let’s go to the official Docker website and download Docker desktop
    https://www.docker.com/products/docker-desktop

2. Once the setup is downloaded, install Docker, ensure that “Enable WSL2 Windows features” is selected while you open up the setup and proceed with installation.

Soon you will see that docker has installed. Hooray!!! We have now successfully installed Docker.

3. Let’s try to run the “getting-started” container using ubuntu terminal:

The Docker Dashboard:

Before going too far, I want to highlight the Docker Dashboard, which gives you a quick view of the containers running on your machine. It gives you quick access to container logs, lets you get a shell inside the container, and lets you easily manage container lifecycle (stop, remove, etc.).

If you open the dashboard now, you will see this tutorial running! The container name (beautiful_agnesi below) is a randomly created name. So, you’ll most likely have a different name.

Now your container is running in docker and you can check it by opening http://localhost:80 in the browser where you will see the following page:

With this let me summarize:

  1. Enabled WSL 2 in Windows 10 Home
  2. Installed a Linux distribution
  3. Added the remote WSL extension to VS Code
  4. Installed Docker Desktop for WSL
  5. Pulled the first sample container (getting-started)

So with all this, we are all set to now develop in a Linux environment, a running Docker engine all without leaving the comforts of having a complex Dual boot OS. Personally I am really excited in the direction Microsoft is taking Windows. All this is happy news for every developer who always wanted the best of both worlds. Before I end this blog I wanted to share a tip that is important for every developer new to this WSL for optimum performance and that is to have all your project files inside the Linux distribution.
To find out more about Docker development best practices go here

In my next blog, I will walk you through a tutorial where I would be teaching to create our first Docker image and run it inside your Linux kernel.

--

--

Follows Microsoft, Tesla Motors, SpaceX, Google, Elon Musk. Aviation Admirer!