Skip to content

Instantly share code, notes, and snippets.

@minanagehsalalma
Created April 6, 2025 23:11
Show Gist options
  • Save minanagehsalalma/2bf814e23df685f86a82a4a6e2634f93 to your computer and use it in GitHub Desktop.
Save minanagehsalalma/2bf814e23df685f86a82a4a6e2634f93 to your computer and use it in GitHub Desktop.
Fix Docker Engine stopped WSL error powershell script
# Run as Administrator
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning "Please run this script as Administrator"
break
}
Write-Host "Fixing WSL2 and Docker Desktop installation..." -ForegroundColor Green
# Enable required Windows features
Write-Host "Step 1: Enabling required Windows features..." -ForegroundColor Cyan
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# Set WSL2 as default
Write-Host "Step 2: Setting WSL2 as default version..." -ForegroundColor Cyan
wsl --set-default-version 2
# Enable Hyper-V and Containers features (which include the required HCS service)
Write-Host "Step 3: Enabling Hyper-V and Containers..." -ForegroundColor Cyan
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Containers -All -NoRestart
Write-Host "Step 4: Checking for existing Docker Desktop WSL distros..." -ForegroundColor Cyan
$existingDistros = wsl --list
if ($existingDistros -match "docker-desktop") {
Write-Host "Found existing docker-desktop distro, unregistering..." -ForegroundColor Yellow
wsl --unregister docker-desktop
}
if ($existingDistros -match "docker-desktop-data") {
Write-Host "Found existing docker-desktop-data distro, unregistering..." -ForegroundColor Yellow
wsl --unregister docker-desktop-data
}
Write-Host "Step 5: Restart required to complete the installation" -ForegroundColor Red
Write-Host "After restarting, launch Docker Desktop again - it should now be able to create the WSL2 distributions" -ForegroundColor Green
$restart = Read-Host "Do you want to restart now? (y/n)"
if ($restart -eq "y") {
Restart-Computer
}
here is the error that used to show
deploying WSL2 distributions
ensuring main distro is deployed: deploying "docker-desktop": importing WSL distro "The operation could not be started because a required feature is not installed. \r\nError code: Wsl/Service/RegisterDistro/CreateVm/HCS/HCS_E_SERVICE_NOT_AVAILABLE\r\n" output="docker-desktop": exit code: 4294967295: running WSL command wsl.exe C:\WINDOWS\System32\wsl.exe --import docker-desktop <HOME>\AppData\Local\Docker\wsl\main C:\Program Files\Docker\Docker\resources\wsl\wsl-bootstrap.tar --version 2: The operation could not be started because a required feature is not installed.
Error code: Wsl/Service/RegisterDistro/CreateVm/HCS/HCS_E_SERVICE_NOT_AVAILABLE
: exit status 0xffffffff
checking if isocache exists: CreateFile \\wsl$\docker-desktop-data\isocache\: The network name cannot be found.
![The Image from the UI](https://gist.github.com/user-attachments/assets/c1b79eef-9ea3-4567-89de-b2edc924f002)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment