Docker Tutorial

3. Docker on Windows with WSL2: Complete Installation & Setup Guide

🐳 Docker Installation & Setup on Windows with WSL2 β€” Complete Guide

Follow this step-by-step tutorial to get Docker running on Windows using WSL2, enabling a full Linux container environment seamlessly integrated with Windows.

βš™οΈ Step 1: Enable WSL2 on Windows

Open PowerShell as Administrator and run:

wsl --install

This installs the Windows Subsystem for Linux and Ubuntu (default). Then, restart your computer.

βœ… After reboot, check WSL version:

wsl -l -v

Ensure Ubuntu is showing as Version 2.

🧩 Step 2: Install Docker Desktop for Windows

  • Download Docker Desktop: https://www.docker.com/products/docker-desktop
  • During setup, enable β€œUse WSL 2 based engine”
  • After installation, open Docker Desktop. It should automatically create docker-desktop and docker-desktop-data.
  • Ensure Docker Desktop is running:
net start com.docker.service

(If already running, you’ll see confirmation)

🐧 Step 3: Open Ubuntu (WSL2)

Launch Ubuntu from Start Menu or PowerShell:

wsl -d Ubuntu-22.04

Now you’re inside a Linux environment on Windows.

πŸ” Step 4: Verify Docker Connection

Run:

docker version

If you see both Client and Server information β€” success! You’re connected to the Docker Engine running in docker-desktop.

πŸš€ Step 5: Run Your First Container

Try the official test image:

docker run hello-world

It should display:

β€œHello from Docker! Your installation appears to be working correctly.”

🌐 Step 6: Run an NGINX Web Server

Test with a real web app:

docker run -d -p 8080:80 nginx

Then open your browser at: http://localhost:8080

You’ll see the Nginx welcome page, confirming container networking works perfectly.

🧠 How Docker Works with WSL2

  • docker-desktop β†’ runs the Docker Engine
  • docker-desktop-data β†’ stores images, containers, and volumes

When you type docker in Ubuntu, the CLI talks to the Docker daemon through a local socket shared between WSL2 instances. This design gives you:

  • Native Linux performance
  • No need for VirtualBox or Hyper-V
  • Seamless integration between Windows and Linux filesystems

βœ… Quick Verification Checklist

Task Command Status
Check WSL2 running wsl -l -v βœ… Ubuntu & docker-desktop
Check Docker service net start com.docker.service βœ… Running
Verify Docker Engine docker version βœ… Client + Server OK
Test container docker run hello-world βœ… Works
Run NGINX docker run -d -p 8080:80 nginx βœ… Webpage loads

🎯 Conclusion

You now have:

  • Docker running on Windows using WSL2
  • Full Linux-based container environment
  • Ability to build, run, and deploy containers directly from Ubuntu

Next steps:

  • Build your own images with a Dockerfile
  • Manage containers with docker-compose
  • Use VS Code + Remote Containers for development

Leave a Reply

Your email address will not be published. Required fields are marked *