DEV Community

Cover image for Setting Up Docker on Windows with WSL2
kristarking
kristarking

Posted on

Setting Up Docker on Windows with WSL2

If you want to run Docker on Windows efficiently, setting up WSL2 (Windows Subsystem for Linux) is essential. This guide walks you through installing Docker, enabling virtualization, setting up WSL2, and confirming that Docker runs successfully.


Step 1: Install Docker for Windows

First, download and install Docker Desktop for Windows from the official Docker website:

๐Ÿ”— Download Docker Desktop

  1. Download the Docker Desktop installer.
  2. Run the installer and follow the on-screen instructions.
  3. Ensure "WSL2 Integration" is enabled during the installation process.
  4. Restart your computer if prompted.

Step 2: Enable Virtualization

Before using Docker, ensure that virtualization is enabled on your system.

  1. Press Ctrl + Shift + Esc to open Task Manager.
  2. Navigate to the Performance tab.
  3. Check if Virtualization is enabled.
    • If it's disabled, enable it from your system's BIOS settings.

Docker Image description 1

Step 3: Install WSL2

Docker relies on WSL2 for better performance and compatibility. Follow these steps to set it up:

  1. Download the WSL2 Linux kernel update package from the Microsoft website: ๐Ÿ”— WSL2 Kernel Update
  2. Install the package by following the prompts.
  3. Open Command Prompt as Administrator and run:
   wsl --set-default-version 2
Enter fullscreen mode Exit fullscreen mode

Step 4: Install Ubuntu for WSL2

After enabling WSL2, install a Linux distribution such as Ubuntu.

  1. Open Microsoft Store.
  2. Search for Ubuntu.
  3. Click Get to download and install it.
  4. Launch Ubuntu and complete the initial setup (username & password).

ubuntu Image description

Step 5: Update WSL

To ensure WSL is up to date, run:

wsl --update
Enter fullscreen mode Exit fullscreen mode

This keeps your WSL2 environment optimized for Docker.


Step 6: Run Docker to Confirm It's Working

  1. Open Docker Desktop.
  2. Wait for it to start and ensure there are no errors.
  3. Open Command Prompt or PowerShell, then run:
   docker --version
Enter fullscreen mode Exit fullscreen mode

This should display the installed Docker version.

  1. Test Docker with a simple container:
   docker run hello-world
Enter fullscreen mode Exit fullscreen mode

If everything is set up correctly, Docker will pull and run the test container successfully.


Docker Image description 2

Conclusion

With these steps, you have successfully installed Docker on Windows with WSL2. Now, you can run Linux-based containers seamlessly on your system. ๐Ÿš€

Top comments (0)