88 lines
3.0 KiB
PowerShell
88 lines
3.0 KiB
PowerShell
# Check Docker images and fix registry
|
|
param(
|
|
[string]$Server = "45.249.208.118",
|
|
[string]$User = "root",
|
|
[string]$Password = "lxvhNYFZ4160"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "Check Docker Images and Registry" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
$plinkPath = "C:\Program Files\PuTTY\plink.exe"
|
|
if (-not (Test-Path $plinkPath)) {
|
|
Write-Host "Error: plink.exe not found" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# Check existing images
|
|
Write-Host "[1/3] Checking existing Docker images..." -ForegroundColor Yellow
|
|
$checkImagesCmd = "docker images | grep -E 'node|REPOSITORY' | head -10"
|
|
$plinkCmd = "`"$plinkPath`" -ssh -pw `"$Password`" -batch ${User}@${Server} `"$checkImagesCmd`""
|
|
$result = cmd /c $plinkCmd 2>&1
|
|
Write-Host $result
|
|
Write-Host ""
|
|
|
|
# Test different mirror sources
|
|
Write-Host "[2/3] Testing mirror sources..." -ForegroundColor Yellow
|
|
|
|
$mirrors = @(
|
|
"https://docker.mirrors.ustc.edu.cn",
|
|
"https://hub-mirror.c.163.com",
|
|
"https://mirror.baidubce.com"
|
|
)
|
|
|
|
foreach ($mirror in $mirrors) {
|
|
Write-Host " Testing: $mirror" -ForegroundColor Gray
|
|
|
|
# Create daemon.json with this mirror
|
|
$daemonJson = @"
|
|
{
|
|
"registry-mirrors": ["$mirror"]
|
|
}
|
|
"@
|
|
|
|
$tempDaemonJson = Join-Path $env:TEMP "daemon-test-$(Get-Random).json"
|
|
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
|
|
$bytes = $utf8NoBom.GetBytes($daemonJson)
|
|
[System.IO.File]::WriteAllBytes($tempDaemonJson, $bytes)
|
|
|
|
# Upload and test
|
|
$pscpPath = "C:\Program Files\PuTTY\pscp.exe"
|
|
$pscpCmd = "`"$pscpPath`" -pw `"$Password`" -batch `"$tempDaemonJson`" ${User}@${Server}:/tmp/daemon-test.json"
|
|
cmd /c $pscpCmd 2>&1 | Out-Null
|
|
|
|
$applyCmd = "sudo cp /tmp/daemon-test.json /etc/docker/daemon.json && sudo systemctl restart docker && sleep 3 && docker pull node:18-alpine 2>&1 | head -5"
|
|
$plinkCmd = "`"$plinkPath`" -ssh -pw `"$Password`" -batch ${User}@${Server} `"$applyCmd`""
|
|
$testResult = cmd /c $plinkCmd 2>&1
|
|
|
|
if ($testResult -match "Downloaded|Pulled|already exists") {
|
|
Write-Host " ✓ Success with $mirror" -ForegroundColor Green
|
|
Write-Host $testResult
|
|
Remove-Item $tempDaemonJson -Force -ErrorAction SilentlyContinue
|
|
break
|
|
} else {
|
|
Write-Host " ✗ Failed with $mirror" -ForegroundColor Red
|
|
}
|
|
|
|
Remove-Item $tempDaemonJson -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# Check if we can use existing image
|
|
Write-Host "[3/3] Checking if we can use existing node image..." -ForegroundColor Yellow
|
|
$checkNodeCmd = "docker images node:18-alpine"
|
|
$plinkCmd = "`"$plinkPath`" -ssh -pw `"$Password`" -batch ${User}@${Server} `"$checkNodeCmd`""
|
|
$result = cmd /c $plinkCmd 2>&1
|
|
Write-Host $result
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "Check complete" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|