🐳 Install Docker in WSL2 Ubuntu (No Docker Desktop)

If you’re a developer using WSL2 (Windows Subsystem for Linux), you don’t need Docker Desktop to run containers. You can install Docker directly inside your WSL2 Ubuntu distro, making your environment leaner, faster, and closer to real Linux systems.


βœ… Why Install Docker Directly in WSL2?

Here are the key benefits:

πŸš€ Lightweight & Fast

  • No background services or system tray apps.
  • Faster boot and runtime performance.
  • Lower memory and CPU usage.

πŸ”’ No Licensing Issues

  • Docker Desktop is free for personal use, but has licensing terms for businesses.
  • Docker CLI in WSL2 is 100% open-source and free.

🐧 Native Linux Behavior

  • Avoid Windows-specific quirks.
  • Same setup as a real Linux server or CI environment.

πŸ’» Terminal-First Development

  • Seamless integration with tools like Git, Node.js, .NET, and Python inside WSL2.
  • Ideal for scripting and automation.

πŸ›  How to Install Docker in WSL2 Ubuntu

🧱 Prerequisites

  • WSL2 installed on Windows 10/11.
  • Ubuntu 22.04 or similar installed via Microsoft Store.

πŸ“¦ Step-by-Step Installation

Open your WSL Ubuntu terminal and run the following:

# Update packages
sudo apt update && sudo apt upgrade -y

# Install Docker dependencies
sudo apt install -y ca-certificates curl gnupg lsb-release

# Add Docker’s official GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
  sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# Add Docker's stable repository
echo \
  "deb [arch=$(dpkg --print-architecture) \
  signed-by=/etc/apt/keyrings/docker.gpg] \
  https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Update and install Docker Engine
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io

# Start Docker service
sudo service docker start

# Add your user to the docker group (optional)
sudo usermod -aG docker $USER

Then restart your terminal or WSL session:

exit
# then reopen Ubuntu

You can now test:

docker --version
docker run hello-world

βš™ Useful Tips for Using Docker in WSL2

πŸ“ 1. Keep Projects in WSL’s Native Filesystem

For best performance, store code in /home/<youruser>/projects/ instead of /mnt/c/....

mkdir -p ~/projects/my-app
cd ~/projects/my-app

Accessing Windows files through /mnt/c/ is much slower for Docker I/O.


🧼 2. Clean Up Regularly

Free disk space by removing unused containers and images:

docker system prune -af

🐚 3. Start Docker on Demand (Optional)

Avoid Docker always running in the background:

sudo service docker start   # start when needed
sudo service docker stop    # stop to save memory

You can also add this to your .bashrc or .zshrc:

alias docker-start="sudo service docker start"
alias docker-stop="sudo service docker stop"

🧰 4. Enable Docker Compose v2 (Optional)

If you use Compose:

docker compose version  # v2 is integrated in docker-ce

Use docker compose (with a space) instead of the legacy docker-compose.


πŸ§ͺ Summary

Installing Docker directly inside WSL2 Ubuntu is the preferred choice for power users and developers who want a clean, fast, and production-like environment.

It’s ideal for:

  • .NET, Node.js, and Python developers
  • Running PostgreSQL, Redis, or other services locally
  • Using Docker Compose for multi-container apps
Scroll to Top