Docker Desktop makes local container development easy, but its strict licensing terms lead many developers to seek alternative approaches. Running Docker Engine directly inside WSL 2 is one such solution, giving you native Linux performance, total control over your setup, and zero licensing restrictions.
By exposing the Docker daemon over TCP, you can transform a single WSL 2 distribution into a shared container host—giving your Windows terminal and secondary WSL environments instant, seamless access to the exact same Docker engine.
+-----------------------------------------------------------------------+
| WINDOWS HOST OS |
| +---------------------------+ +-------------------------------+ |
| | Windows Terminal | | Secondary WSL Distro | |
| | (PowerShell / CMD) | | (e.g., Ubuntu-Debian) | |
| | docker-cli | | docker-ce-cli | |
| +-------------+-------------+ +---------------+---------------+ |
| | | |
| +-----------------+-----------------+ |
| | |
| DOCKER_HOST = tcp://127.0.0.1:2375 |
| | |
| v |
| +-----------------------------------------------------------------+ |
| | PRIMARY WSL DISTRO | |
| | +-----------------------------------------------------------+ | |
| | | Docker Engine (dockerd) | | |
| | | Listening on: | | |
| | | - unix:///var/run/docker.sock | | |
| | | - tcp://127.0.0.1:2375 | | |
| | +-----------------------------------------------------------+ | |
| +-----------------------------------------------------------------+ | |
+-----------------------------------------------------------------------+
Here are step-by-step
Step 1: Set Up the Primary WSL Host
Install Docker Engine
sudo apt update && sudo apt upgrade -y && \
sudo apt install -y ca-certificates curl gnupg lsb-release && \
sudo install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
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 && \
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && \
sudo usermod -aG docker $USER && \
sudo systemctl enable --now docker
Override Docker’s systemd unit file
- Open the
docker.service
sudo systemctl edit docker.service
- Paste the following content
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://127.0.0.1:2375
Ensure it's always ready when all its terminals closed
- Modify the
wsl.confby
sudo vi /etc/wsl.conf
- Paste the following content
[boot]
systemd=true
Restart services
sudo systemctl daemon-reload && \
sudo systemctl restart docker && \
sudo systemctl enable docker
Step 2: Setting WSL Docker Client
Install docker-ce-cli
sudo apt-get update && \
sudo apt-get install -y ca-certificates curl gnupg && \
sudo install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
sudo chmod a+r /etc/apt/keyrings/docker.gpg && \
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null && \
sudo apt-get update && \
sudo apt-get install -y docker-ce-cli
Define DOCKER_HOST in ~/.zshrc
export DOCKER_HOST=tcp://127.0.0.1:2375
Verify
source ~/.zshrc && docker ps -a
Step 3: Setting for Windows as Docker Client
Install docker-cli
winget install Docker.DockerCLI
Define DOCKER_HOST
[System.Environment]::SetEnvironmentVariable('DOCKER_HOST', "tcp://127.0.0.1:2375", 'User')
Verify
docker ps -a
Notes
After wsl --shutdown or restarted Windows
- You have to open the terminal of WSL-Docker-Host first
If Testcontainer is being using
It needs to be disable RYUK
- For WSL, by modifying
~/.zshrc
export TESTCONTAINERS_RYUK_DISABLED = true
- For Windows, by
[System.Environment]::SetEnvironmentVariable('TESTCONTAINERS_HOST_OVERRIDE', "127.0.0.1", 'User') && `
[System.Environment]::SetEnvironmentVariable('TESTCONTAINERS_RYUK_DISABLED', "true", 'User')
Top comments (0)