Run Docker on WSL2 Without Docker Desktop 🐳

Let’s install Docker inside a WSL2 Linux distro, configure it to run without sudo, set up auto-start on launch, and enable log rotation to keep things clean—all without the bloated Docker Desktop.

Docker Desktop isn’t just unnecessary—it’s heavy, intrusive, and now comes with licensing restrictions. Running Docker natively inside WSL2 is faster, lighter, and fully under your control. Let’s set it up the right way.

Prerequisites āœ…

  • WSL2 already installed
  • Ubuntu (or another Linux distro Debian based for this article) running under WSL2

Install Docker (Inside WSL2) šŸ”§

To install the Docker Community Engine, let's run the following script.

# Update your package lists and upgrade existing packages 
$ sudo apt update && sudo apt upgrade -y

# Install necessary packages to allow apt to use repositories over HTTPS
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common -y

# 🐳 Download and save Docker’s official GPG key
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
    sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# 🐳 Add Docker’s stable repository to your APT sources list
$ echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
    sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Update package index again, now with Docker packages included
$ sudo apt update

# 🐳 Finally, install the Docker Engine
$ sudo apt install docker-ce -y

šŸ› ļø Running Docker Without SUDO

Nobody want's to type sudo for every command in our development machine.
Here is how set up.

# Create the 'docker' group (if it doesn't already exist)
# This group allows running Docker commands without 'sudo'
$ sudo groupadd docker

# Add your current user to the 'docker' group
$ sudo usermod -aG docker $USER

# Apply the new group membership immediately
# This avoids the need to log out and back in
$ newgrp docker

šŸš€ Wrapping up

$ sudo service docker start

$ docker run hello-world

āš™ļø Optional: Auto-Start Docker on WSL Launch

Append this to ~/.bashrc or ~/.profile:

# Check if the current environment is WSL2
if grep -q "\-WSL2" /proc/version > /dev/null 2>&1; then

    # Check if the Docker service is not running
    if service docker status 2>&1 | grep -q "is not running"; then

        # Start the Docker service as root using WSL's built-in mechanism
        # This avoids needing sudo manually each time
        wsl.exe --distribution "${WSL_DISTRO_NAME}" --user root \
            --exec /usr/sbin/service docker start > /dev/null 2>&1
    fi
fi

Checks if the docker service isn't running and start it.

This code runs on the bash startup.

Configuring Docker: Daemon Settings + Log Rotation

To prevent Docker logs from eating up your disk space, configure log rotation:

$ sudo nano /etc/docker/daemon.json

Paste this:

{
  "host": "unix:///var/run/docker.sock",
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}
  • max-size: rotates when logs hit 10MB
  • max-file: keeps 3 files max, older logs get purged

Then restart Docker:

$ sudo service docker restart
You can adjust size or count based on your storage needs.

šŸ› ļø Common Issues

  • Permission denied on docker
    → You forgot the group step or didn't apply it (newgrp docker)
  • Daemon not running
    → Run sudo service docker start

WSL version issues
→ Check:

$ wsl --list --verbose

āœ… Summary

Task Command
Install Docker Add repo & install docker-ce
Start Docker daemon sudo service docker start
Run as non-root usermod -aG docker $USER && newgrp docker
Test Docker docker run hello-world
Configure log rotation Edit /etc/docker/daemon.json and restart daemon
Auto-start Docker on launch Add script to .bashrc or .profile

No Docker Desktop. No junk. Just containers running clean and fast inside WSL2 — with logs under control.

Love Discord?