File size: 5,318 Bytes
5a81b95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Configure Docker Desktop to use D:\dOCKER
# Run as Administrator

param(
    [string]$DockerPath = "D:\dOCKER"
)

Write-Host "🐳 Docker Windows Path Configuration" -ForegroundColor Cyan
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host ""

# Check if running as Administrator
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
    Write-Host "❌ This script must be run as Administrator!" -ForegroundColor Red
    Write-Host "Right-click PowerShell and select 'Run as Administrator'" -ForegroundColor Yellow
    exit 1
}

# Check if Docker Desktop is running
Write-Host "πŸ“‹ Checking Docker Desktop status..." -ForegroundColor Yellow
$dockerRunning = Get-Process "Docker Desktop" -ErrorAction SilentlyContinue
if ($dockerRunning) {
    Write-Host "⚠️  Docker Desktop is running. Please close it before continuing." -ForegroundColor Yellow
    $response = Read-Host "Close Docker Desktop now? (Y/N)"
    if ($response -eq "Y" -or $response -eq "y") {
        Stop-Process -Name "Docker Desktop" -Force -ErrorAction SilentlyContinue
        Start-Sleep -Seconds 3
    } else {
        Write-Host "❌ Please close Docker Desktop manually and run this script again." -ForegroundColor Red
        exit 1
    }
}

# Check if path exists
if (-not (Test-Path $DockerPath)) {
    Write-Host "❌ Path does not exist: $DockerPath" -ForegroundColor Red
    Write-Host "Creating directory..." -ForegroundColor Yellow
    New-Item -ItemType Directory -Path $DockerPath -Force | Out-Null
}

# Check WSL distributions
Write-Host ""
Write-Host "πŸ“‹ Checking WSL distributions..." -ForegroundColor Yellow
$wslList = wsl --list --verbose 2>&1
Write-Host $wslList

# Check if docker-desktop-data exists
$hasDockerData = $wslList -match "docker-desktop-data"
$hasDockerDesktop = $wslList -match "docker-desktop"

if ($hasDockerData -or $hasDockerDesktop) {
    Write-Host ""
    Write-Host "⚠️  Docker Desktop WSL distributions found." -ForegroundColor Yellow
    Write-Host "You have two options:" -ForegroundColor Yellow
    Write-Host ""
    Write-Host "Option 1: Use Docker Desktop Settings (Recommended)" -ForegroundColor Cyan
    Write-Host "  1. Open Docker Desktop" -ForegroundColor White
    Write-Host "  2. Go to Settings β†’ Resources β†’ Advanced" -ForegroundColor White
    Write-Host "  3. Change 'Disk image location' to: $DockerPath" -ForegroundColor White
    Write-Host "  4. Click 'Apply & Restart'" -ForegroundColor White
    Write-Host ""
    Write-Host "Option 2: Manual WSL Migration (Advanced)" -ForegroundColor Cyan
    Write-Host "  See DOCKER_WINDOWS_CONFIG.md for detailed instructions" -ForegroundColor White
    Write-Host ""
} else {
    Write-Host "βœ… No Docker Desktop WSL distributions found." -ForegroundColor Green
    Write-Host "Docker Desktop will use default location or configured path." -ForegroundColor Green
}

# Verify Docker path structure
Write-Host ""
Write-Host "πŸ“ Checking Docker path structure..." -ForegroundColor Yellow
$expectedPath = Join-Path $DockerPath "wsl\DockerDesktopWSL\data"
if (Test-Path $expectedPath) {
    Write-Host "βœ… Found Docker data at: $expectedPath" -ForegroundColor Green
    
    # List contents
    Write-Host ""
    Write-Host "Contents:" -ForegroundColor Cyan
    Get-ChildItem -Path $expectedPath -Recurse -Depth 2 | Select-Object FullName, Length | Format-Table -AutoSize
} else {
    Write-Host "⚠️  Expected path not found: $expectedPath" -ForegroundColor Yellow
    Write-Host "This is normal if Docker Desktop hasn't been configured yet." -ForegroundColor Yellow
}

# Check .wslconfig
Write-Host ""
Write-Host "πŸ“‹ Checking .wslconfig..." -ForegroundColor Yellow
$wslConfigPath = "$env:USERPROFILE\.wslconfig"
if (Test-Path $wslConfigPath) {
    Write-Host "βœ… Found .wslconfig at: $wslConfigPath" -ForegroundColor Green
    Write-Host ""
    Write-Host "Current content:" -ForegroundColor Cyan
    Get-Content $wslConfigPath
} else {
    Write-Host "⚠️  .wslconfig not found. Creating template..." -ForegroundColor Yellow
    
    $wslConfigContent = @"
[wsl2]
# Memory limit (adjust based on your system)
memory=4GB

# CPU cores (adjust based on your system)
processors=2

# Swap file location
swap=$($DockerPath.Replace('\', '\\'))\\wsl\\swap.vhdx

# Page reporting (better performance)
pageReporting=true

# VM idle timeout
vmIdleTimeout=60000
"@
    
    $wslConfigContent | Out-File -FilePath $wslConfigPath -Encoding UTF8
    Write-Host "βœ… Created .wslconfig at: $wslConfigPath" -ForegroundColor Green
}

# Summary
Write-Host ""
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host "βœ… Configuration Check Complete" -ForegroundColor Green
Write-Host ""
Write-Host "Next Steps:" -ForegroundColor Yellow
Write-Host "1. Open Docker Desktop" -ForegroundColor White
Write-Host "2. Go to Settings β†’ Resources β†’ Advanced" -ForegroundColor White
Write-Host "3. Set 'Disk image location' to: $DockerPath" -ForegroundColor White
Write-Host "4. Click 'Apply & Restart'" -ForegroundColor White
Write-Host ""
Write-Host "For detailed instructions, see: DOCKER_WINDOWS_CONFIG.md" -ForegroundColor Cyan
Write-Host ""