How to Fix Docker WSL2 Integration Error
In this tutorial, you'll learn about How to Fix Docker WSL2 Integration Error. We cover key concepts, practical examples, and best practices.
Docker commands from WSL2 return Cannot connect to the Docker daemon or Docker Desktop shows WSL2 integration not enabled — Docker Desktop cannot communicate with your WSL2 distribution.
The Problem
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock.
Is the docker daemon running?
Or Docker Desktop shows a warning that WSL2 integration is not working.
Step-by-Step Fix
Step 1: Verify WSL2 is installed and set as default
wsl --status
Expected:
Default Distribution: Ubuntu
Default Version: 2
If not, set WSL2 as default:
wsl --set-default-version 2
Step 2: Enable WSL2 integration in Docker Desktop
- Open Docker Desktop → Settings → Resources → WSL Integration
- Ensure "Enable integration with my default WSL distro" is checked
- Select your WSL distro (Ubuntu, Debian, etc.)
- Apply & Restart
Step 3: Restart Docker Desktop
# From PowerShell as admin
Restart-Service docker
Or restart Docker Desktop from the system tray.
Step 4: Verify from WSL2
Open your WSL2 terminal:
docker ps
Expected:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Step 5: Check the Docker socket in WSL2
ls -la /var/run/docker.sock
Expected:
srwxrwxr-x 1 root docker 0 ... /var/run/docker.sock
Step 6: Check Docker context
docker context ls
Ensure the active context is default (not a remote context).
Prevention Tips
- Enable WSL2 integration in Docker Desktop settings before using Docker from WSL
- Keep Docker Desktop and WSL2 updated
- Use the same WSL distro consistently for Docker work
- Restart Docker Desktop after WSL2 updates
- Do not install Docker Engine inside WSL2 when using Docker Desktop
Common Mistakes with wsl error
- Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists - Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
These mistakes appear frequently in real-world DOCKER code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro