Install Docker on WSL2 Without Docker Desktop: A Complete Guide
Learn how to install Docker Engine directly in a WSL2 Linux distribution without Docker Desktop. This guide covers prerequisites, repository and signing-key configuration, user permissions, optional registry mirrors, systemd support, installation checks, and common troubleshooting steps.
1. Why Install Docker Directly in WSL2?
A common way to run containers on Windows is to install a desktop container-management application that uses a WSL2 backend. For developers who only need Docker Engine, however, a direct installation inside a WSL2 distribution can be a better fit.
- Less desktop-management overhead. Desktop applications typically include a graphical interface, background processes, and additional management components. Installing the engine directly avoids these extras.
- Better filesystem performance when projects stay in Linux. Accessing Windows-mounted directories from WSL2 involves cross-filesystem I/O. Keeping both Docker Engine and project files inside the Linux distribution can improve build and bind-mount performance. The location of the project files is important—not just how Docker is installed.
- A workflow closer to production Linux. Most production container hosts run Linux. Using Docker directly in a WSL2 distribution provides familiar Linux commands, directory structures, and permissions, reducing differences between local development and production.
- More control over engine versions. You can choose Docker Community Edition versions and manage updates independently of a desktop application’s release cycle.
The installation itself is straightforward, but repository configuration, signing keys, permissions, and service management are common sources of problems. The following steps cover the process in order.
2. Check the Prerequisites
Confirm That Your Distribution Uses WSL2
Run this command in PowerShell:
wsl -l -v
Check that the target distribution shows 2 in the VERSION column. If it shows 1, convert it:
wsl --set-version <distribution-name> 2
WSL2 uses a lightweight virtual machine with a full Linux kernel. Docker Engine depends on kernel features such as namespaces, cgroups, and OverlayFS, so this direct-installation approach requires WSL2.
Trying to run the engine inside WSL1 can lead to missing-kernel-feature errors or a Cannot connect to the Docker daemon message.
Check the Linux Distribution Version
Use a recent mainstream Linux distribution, such as a recent Ubuntu or Debian release. Older distributions may have outdated packages or repositories that complicate container-runtime installation.
Check the distribution version with:
lsb_release -a
The installation commands below use apt and are intended for Ubuntu/Debian-based environments.
3. Install Docker Engine
Remove Older or Conflicting Packages
Distribution repositories may contain older Docker or container-runtime packages that conflict with Docker Engine packages. Remove them first:
sudo apt-get remove -y docker docker-engine docker.io containerd runc 2>/dev/null || true
Install the Required Utilities
sudo apt-get updatesudo apt-get install -y ca-certificates curl gnupg
Configure the Repository and GPG Key
Use the appropriate Docker package repository for your distribution. If access to the official repository is slow or restricted on your network, a suitable repository mirror may be necessary.
Two details commonly cause installation failures.
Pitfall 1: The Signing-Key Format and Location
Store the repository key in /etc/apt/keyrings/ and reference it explicitly through signed-by. The key format must match the file being used.
The example below converts the downloaded key to a binary GPG keyring:
sudo install -m 0755 -d /etc/apt/keyringscurl -fsSL <repository-signing-key-url> | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgsudo chmod a+r /etc/apt/keyrings/docker.gpg
Replace <repository-signing-key-url> with the key address provided by the repository or mirror you intend to use.
An incorrect key path, unreadable key file, or mismatched key format can cause signature-verification errors during apt-get update.
Pitfall 2: A Repository That Does Not Match the Distribution
The repository must support your distribution and its release codename. Copying someone else’s repository configuration can produce 404 Not Found errors if their release differs from yours.
Use the following structure:
echo \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \<docker-repository-url> $(lsb_release -cs) stable" | \sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Replace <docker-repository-url> with the appropriate package repository or mirror URL for your distribution. The command obtains the architecture and release codename automatically, but the selected repository must provide packages for that release.
Install the Engine and Plugins
sudo apt-get updatesudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Docker Compose is provided here as a plugin. Its command is:
docker compose
This differs from the older standalone docker-compose command. Mixing the two can cause confusion when following instructions or running scripts.
4. Configure User Permissions
By default, access to the Docker daemon requires root privileges or membership in the docker group. Running every command with sudo is inconvenient and can create file-ownership problems in development projects.
Add your current user to the group:
sudo usermod -aG docker $USER
The group change does not take effect in your existing session. Log out and reopen your WSL session. Alternatively, run the following in PowerShell, then reopen the distribution:
wsl --shutdown
Check your active group membership:
groups
If Docker still reports permission denied, confirm that docker appears in the output and that you have started a new session since changing the group membership.
Security note: Membership in the docker group effectively grants root-level privileges. Only add trusted users.
5. Configure an Optional Registry Mirror
If image pulls from the default registry frequently time out because of network restrictions or poor connectivity, you can configure a registry mirror.
Create or edit /etc/docker/daemon.json:
sudo mkdir -p /etc/dockersudo tee /etc/docker/daemon.json <<-'EOF'{"registry-mirrors": ["https://<registry-mirror-address>"]}EOF
Replace the placeholder with the address of a mirror suitable for your environment. Mirror availability and access requirements vary; do not assume that a mirror available in one region is accessible everywhere.
If daemon.json already exists, merge the setting into its existing JSON rather than overwriting other configuration.
Restart Docker:
sudo systemctl daemon-reloadsudo systemctl restart docker
Verify that Docker recognizes the mirror:
docker info | grep -A 5 "Registry Mirrors"
WSL2 Pitfall: systemctl Requires systemd
A WSL distribution using an older init setup instead of systemd will not support these systemctl commands.
To enable systemd, add the following setting to /etc/wsl.conf:
[boot]systemd=true
Then run this command in PowerShell and reopen the distribution:
wsl --shutdown
Systemd support requires a sufficiently recent WSL version. If your installed version does not support it, update WSL first.
6. Verify the Installation
Run these commands in your Linux distribution:
# Display client and server version informationdocker version# Run a test containerdocker run --rm hello-world# List running containersdocker ps
If hello-world prints its welcome message, the client can communicate with the daemon, pull an image, and create and run a container.
Practical Tips for Daily Use
- Keep project files in the Linux filesystem. Use a directory such as
~/projectsrather than/mnt/c/.... This avoids cross-filesystem I/O and can substantially improve build and bind-mount performance. - Configure log rotation. Container logs can grow until they consume available disk space. Configure
max-sizeandmax-fileunderlog-optsindaemon.jsonto limit log growth. - Watch WSL2 memory usage. WSL2 memory use can grow during builds and other workloads, and memory reclamation can be a concern. To cap the virtual machine’s memory and configure swap, create or edit
.wslconfigin your Windows user directory:
[wsl2]memory=8GBswap=4GB
7. Troubleshooting Checklist
| Symptom | Likely Cause | What to Check or Do |
|---|---|---|
Cannot connect to the Docker daemon |
The service is not running, or the distribution is not using WSL2 | Run sudo systemctl start docker and confirm WSL2 mode |
Signature errors during apt-get update |
An incorrect signing-key path, format, or repository configuration | Check /etc/apt/keyrings/ and the repository’s signed-by setting |
| Image pulls time out | Network connectivity problems or restricted registry access | If appropriate, configure registry-mirrors and restart Docker |
permission denied when connecting to the daemon |
The user is not in the docker group, or the session predates the group change |
Run sudo usermod -aG docker $USER, then reopen the WSL session |
systemctl does not work |
systemd is not enabled | Configure /etc/wsl.conf, then run wsl --shutdown from PowerShell |
8. Summary
Installing Docker Engine directly in WSL2 follows a clear sequence:
Confirm WSL2 → configure the repository and signing key → install the engine and plugins → configure permissions and any necessary registry mirror → verify the installation.
The most important part is understanding the dependencies behind those steps: Docker needs the Linux kernel features provided by WSL2, APT needs a correctly configured repository signing key, group membership changes require a new session, and systemctl requires systemd.
With these pieces in place, you can run Docker from your WSL2 Linux distribution without Docker Desktop—and troubleshoot common failures without repeatedly reinstalling the engine.
