Operations 6 min read

Run Docker Inside WSL on Windows: A Complete Step‑by‑Step Guide

This guide explains why developers need a Linux‑like environment on Windows, outlines Docker’s client‑daemon architecture, and provides detailed prerequisites and configuration steps to enable Docker commands inside WSL, including persistent environment variables and driver sharing.

ITPUB
ITPUB
ITPUB
Run Docker Inside WSL on Windows: A Complete Step‑by‑Step Guide

Background

Developers often work on Windows machines that provide a rich GUI, while production servers run Linux. To keep development and deployment environments consistent, Windows Subsystem for Linux (WSL) can be used instead of a full virtual machine, offering lower resource usage and faster performance (the Linux environment requires only about 200 MB).

Overview of Docker Architecture

Docker consists of three components:

Client : interacts with the REST API to communicate with the daemon.

REST API : serves as the interface between client and server.

Daemon : manages containers (start, stop, etc.) and listens for API requests.

When Docker runs Windows containers, the daemon runs as a Windows process; for Linux containers it runs inside a lightweight Moby Linux VM. The client does not need to be on the same host as the daemon, allowing a WSL client to talk to a Docker daemon on the Windows host.

Prerequisites

Enable Hyper‑V and CPU virtualization in BIOS.

Install Docker for Windows.

Install WSL (preferably WSL 1 or 2).

Configure Docker for Windows

In Docker’s general settings, expose the daemon without TLS so it listens on a TCP endpoint. This is required for WSL to connect. Enable the option highlighted in the screenshot (yellow background) and optionally share your drives under “Shared Drives” if you need file access from WSL.

Docker for Windows settings
Docker for Windows settings

Configure WSL

Inside WSL, install the Docker client package and point it to the Windows daemon:

apt install docker.io
export DOCKER_HOST=tcp://127.0.0.1:2375

Running a Docker command now succeeds without the error “Cannot connect to the Docker daemon…”. However, the DOCKER_HOST variable only lasts for the current session.

To make it permanent, add the export line to ~/.bash_profile or ~/.bashrc. These files can be edited with vi in the SSH terminal. After saving and restarting the Bash console, Docker commands work as expected.

Editing .bashrc
Editing .bashrc

Conclusion

With Windows 10’s productivity improvements, many developers continue to code on Windows while Linux remains the standard server OS. Using WSL eliminates the overhead of a full VM, allowing developers to test Linux‑specific behavior and run Docker containers directly from their familiar Windows environment.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

containerization
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.