Docker

Run Docker in WSL Without Docker Desktop

Docker is a containerized, free, and open-source forum utilized to develop, run and share projects and software. Docker can be used on both Windows and Linux distributions. However, Docker is more suitable for Linux kernels. On Windows, Docker also uses Hyper V for virtual machines. But VM takes a lot of space and requires separate resources such as RAM. For this purpose, WSL is more suitable for using Docker on Windows.

This write-up will describe how to run or use Docker in WSL without the Docker Desktop application.

How to Run Docker in WSL Without Docker Desktop?

To utilize the WSL (Windows Subsystem for Linux) to run the Docker CLI without the Desktop application, first install or enable the WSL on Windows. Then, download any Linux distribution, such as Ubuntu 22.04, and use it to install Docker. For the demonstration, follow the provided instructions.

Step 1: Install WSL Latest Version

First, open the Microsoft Store from the Windows Start menu:

After that, search for WSL and install it. However, users can also utilize the built-in WSL by enabling it from “Windows Features”. But the newest version of WSL is preferable due to its advanced features, such as the “systemd” utility:

Alternatively, you can update the built-in WSL to the Microsoft latest version of WSL using the “wsl –update” command:

wsl --update

For the verification, check out the WSL version:

wsl --version

Step 2: Install Linux Distribution

After installing or enabling WSL on Windows, install any Linux distribution. For instance, we have installed “Ubuntu 22.04.2” on Windows:

Note: Latest version of WSL supports Ubuntu version 20 or more:

Step 3: Set Username and Password

After that, launch the Linux distribution from the Windows “Startup” menu and set the Linux username and password as shown below:

Step 4: Update APT Repository

After that, update the Ubuntu APT repository using the “sudo apt update” command:

sudo apt update

Here, you can see we have successfully updated the apt repository:

Step 5: Install Docker

Next, install the Docker by utilizing the below command. Here, the “-y” option is used to grant the permission to install required packages automatically:

sudo apt install docker.io -y

Step 6: Make a New User

After installation of Docker, make a new user group with the name “docker” by utilizing the below-mentioned command:

sudo usermod -aG docker $User

Step 7: Check Docker Version

For the verification, check out the version of Docker on WSL Linux distribution:

docker --version

Here, you can see we have installed the Docker version “20.10.12”:

Step 8: Shut Down WSL Using PowerShell

Now, shutdown the WSL from the Windows Powershell:

wsl --shutdown

Step 9: Run Docker on Linux Distribution

Again, start the Ubuntu from the Start menu and run the “docker run hello-world” and check if the Docker is working on WSL or not:

docker run hello-world

From the above output, it can be observed that we have successfully run Docker on WSL.

Conclusion

To run or utilize Docker in WSL, first install or enable the WSL on Windows. Then, install any Linux distribution, such as Ubuntu 22.04. Then, install Docker using the “sudo apt install docker.io” command. After that, make the new user group named “docker” and start running Docker on WSL. This write-up has illustrated how to use or run Docker in WSL without using Docker Desktop.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.