To resolve the issue where the docker command is not found in your WSL 1 distribution, you'll need to upgrade your WSL distribution from version 1 to version 2 and enable WSL integration in Docker Desktop. Below are the detailed steps to guide you through this process:
1. Verify Your Windows Version
WSL 2 is available on Windows 10 version 1903 or higher (with Build 18362 or higher) and Windows 11.
- Check Windows Version:
- Press
Win + R, type winver, and press Enter.
- In the dialog that appears, check your Windows version and build number.
If your version is below the required, update Windows:
- Update Windows:
- Go to Settings > Update & Security > Windows Update.
- Click Check for updates and install any available updates.
2. Ensure Virtualization Is Enabled
WSL 2 requires virtualization to be enabled in your BIOS/UEFI settings.
3. Install WSL 2
a. Enable WSL and Virtual Machine Platform Features
-
Open PowerShell as Administrator:
- Press
Win, type PowerShell, right-click on Windows PowerShell, and select Run as administrator.
-
Run the Following Commands:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-
Restart Your Computer to apply the changes.
b. Set WSL 2 as the Default Version
-
Open PowerShell as Administrator again.
-
Set WSL 2 as Default:
wsl --set-default-version 2
c. Update the Linux Kernel (If Necessary)
If prompted, download and install the WSL 2 Linux kernel update package.
- Installation Steps:
- Download the kernel update package from the link above.
- Run the installer and follow the on-screen instructions.
- Restart your computer after installation.
4. Convert Your Existing WSL 1 Distro to WSL 2
-
List Your Installed WSL Distributions:
Open PowerShell and run:
wsl --list --verbose
You'll see output similar to:
NAME STATE VERSION
* Ubuntu Running 1
-
Convert to WSL 2:
Replace Ubuntu with the name of your distribution if different.
wsl --set-version Ubuntu 2
Note: The conversion may take some time depending on the size of your distro.
-
Verify the Conversion:
Run the list command again to ensure the version is now 2.
wsl --list --verbose
You should see:
NAME STATE VERSION
* Ubuntu Running 2
5. Install Docker Desktop
If you haven't installed Docker Desktop yet, follow these steps:
-
Download Docker Desktop:
-
Run the Installer:
- Double-click the downloaded
.exe file and follow the installation prompts.
-
Complete Setup:
- During installation, ensure the option "Enable WSL 2 integration" is selected.
-
Launch Docker Desktop:
- After installation, Docker Desktop should start automatically. If not, launch it from the Start menu.
6. Enable WSL Integration in Docker Desktop
-
Open Docker Desktop Settings:
- Right-click the Docker icon in the system tray and select Settings.
-
Navigate to Resources > WSL Integration:
- In the settings menu, go to Resources (or General in some versions) and then WSL Integration.
-
Enable Integration for Your Distro:
- Toggle Enable integration with my default WSL distro or specifically select your desired distribution (e.g., Ubuntu).
-
Apply & Restart:
- Click Apply & Restart to save the changes.
7. Verify Docker Installation in WSL
-
Open Your WSL Terminal:
- Open the distribution you converted to WSL 2 (e.g., Ubuntu).
-
Check Docker Version:
docker --version
You should see output similar to:
Docker version 24.0.0, build xxxx
-
Run a Test Container:
docker run hello-world
If everything is set up correctly, you should see a message that Docker is working.
Troubleshooting Tips
-
Docker Daemon Not Running:
- Ensure Docker Desktop is running. You can start it from the Start menu if it's not.
-
Permission Issues:
- Make sure your user has the necessary permissions. Sometimes, adding your user to the
docker group helps.
sudo usermod -aG docker $USER
After running the above command, restart your WSL terminal.
-
Network Issues:
- If you encounter network-related errors, restarting Docker Desktop and WSL may help.
wsl --shutdown
Then, restart Docker Desktop.
-
Check Docker Desktop Logs:
- In Docker Desktop, go to Troubleshoot > Get Support to view logs that can help identify issues.
Additional Resources
By following these steps, you should be able to upgrade your WSL distribution to version 2 and integrate Docker Desktop successfully, allowing you to use the docker command within your WSL environment.
If you encounter any issues during this process, feel free to provide specific error messages, and I can assist you further!