Now Windows Subsystem for Linux or known as WSL already support with Docker, it is very helpful for me in software development process. Nowadays, container based technology is a must to have for every software developers. I’ve already used Docker for development process on my machine. Since WSL2 released, i’m install this tool and moving to it for development purpose. Docker is helpful for me because I don’t need to install any software for development like XAMPP, LEMP or LAMP, etc. Because Docker uses container technology, the environment of application isolates the use of its. So, it doesn’t affect your computer (host) and other applications.

Preparation

Before starting the Docker installation on WSL, make sure you have WSL2 installed on your Windows 10 operating system. For those who don’t know how to install WSL2, I recommend you to read Microsoft's official documentation on here.

1. Docker Installation (Ubuntu)

At this writing, I use Ubuntu 20.04 LTS flavor. You can download this flavor on Microsoft Store.

Purge old Docker packages

If you’ve already used WSL, this is recommend for you to remove all installed Docker package on you WSL. Use this command to throw them!

$ sudo apt-get remove docker docker-engine docker.io containerd runc

2. Docker Package Pre-Install

Use this command to update the apt package and allow apt to use a repository over HTTPS:

$ sudo apt-get update

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

3. Add Docker Repository

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

4. Install Docker Engine

$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io

5. Activate Docker Service

Before using Docker, make sure Docker service is running. We can check with this command:

$ sudo service docker status

If it’s not active, run the service with the command:

$ sudo service docker status

6. Check The Docker Installation

The final step is to check if Docker is installed properly. Check it with the following command:

$ sudo docker run hello-world

If successful, it will display something like this: Result of run Hello World Docker

Docker User Configuration

By default, we have to add the sudo command to the start of command. It causes only users who have root or sudo can access Docker. I think this is not effective, especially for development use. Now this step will add the user to the Docker group, so you can run Docker without using the sudo command.

$ sudo usermod -aG docker $USER

After run this command, restart your WSL and run command on step 6 without sudo.

Closing

This is my article about installing Docker on WSL 2 (Windows 10), I hope it’s help you.