117 lines
4.1 KiB
PowerShell
117 lines
4.1 KiB
PowerShell
# Fix Docker registry issue on server
|
|
param(
|
|
[string]$Server = "45.249.208.118",
|
|
[string]$User = "root",
|
|
[string]$Password = "lxvhNYFZ4160"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
Write-Host "Fixing Docker registry configuration..." -ForegroundColor Cyan
|
|
|
|
$plinkPath = "C:\Program Files\PuTTY\plink.exe"
|
|
|
|
if (-not (Test-Path $plinkPath)) {
|
|
Write-Host "Error: plink.exe not found" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "`n[1/3] Testing registry mirrors..." -ForegroundColor Yellow
|
|
|
|
$mirrors = @(
|
|
"https://docker.1panel.live",
|
|
"https://docker.rainbond.cc",
|
|
"https://docker.nju.edu.cn",
|
|
"https://dockerproxy.cn",
|
|
"https://docker.m.daocloud.io"
|
|
)
|
|
|
|
$workingMirrors = @()
|
|
foreach ($mirror in $mirrors) {
|
|
Write-Host "Testing $mirror..." -ForegroundColor Cyan
|
|
$result = & $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "curl -I $mirror/v2/ 2>&1 | head -1"
|
|
if ($result -match "200" -or $result -match "401") {
|
|
Write-Host " [OK] $mirror is working" -ForegroundColor Green
|
|
$workingMirrors += $mirror
|
|
} else {
|
|
Write-Host " [FAIL] $mirror is not working" -ForegroundColor Red
|
|
}
|
|
}
|
|
|
|
Write-Host "`n[2/3] Updating Docker daemon configuration..." -ForegroundColor Yellow
|
|
|
|
if ($workingMirrors.Count -eq 0) {
|
|
Write-Host "No working mirrors found. Using Docker Hub directly..." -ForegroundColor Yellow
|
|
$newConfig = @'
|
|
{
|
|
"log-driver": "json-file",
|
|
"log-opts": {
|
|
"max-size": "20m",
|
|
"max-file": "3"
|
|
}
|
|
}
|
|
'@
|
|
} else {
|
|
Write-Host "Using working mirrors: $($workingMirrors -join ', ')" -ForegroundColor Green
|
|
$mirrorsJson = ($workingMirrors | ForEach-Object { " `"$_`"" }) -join ",`n"
|
|
$newConfig = @"
|
|
{
|
|
"registry-mirrors": [
|
|
$mirrorsJson
|
|
],
|
|
"log-driver": "json-file",
|
|
"log-opts": {
|
|
"max-size": "20m",
|
|
"max-file": "3"
|
|
}
|
|
}
|
|
"@
|
|
}
|
|
|
|
# Backup old config
|
|
Write-Host "Backing up old configuration..." -ForegroundColor Cyan
|
|
& $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "cp /etc/docker/daemon.json /etc/docker/daemon.json.bak"
|
|
|
|
# Write new config
|
|
$tempFile = Join-Path $env:TEMP "daemon.json"
|
|
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
|
|
[System.IO.File]::WriteAllText($tempFile, $newConfig, $utf8NoBom)
|
|
|
|
$pscpPath = "C:\Program Files\PuTTY\pscp.exe"
|
|
& $pscpPath -pw $Password -batch $tempFile "${User}@${Server}:/tmp/daemon.json"
|
|
|
|
# Move to final location
|
|
& $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "mv /tmp/daemon.json /etc/docker/daemon.json"
|
|
|
|
Write-Host "`n[3/3] Restarting Docker..." -ForegroundColor Yellow
|
|
& $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "systemctl restart docker"
|
|
|
|
Write-Host "`nWaiting for Docker to start..." -ForegroundColor Cyan
|
|
Start-Sleep -Seconds 5
|
|
|
|
# Test pulling image
|
|
Write-Host "`nTesting image pull..." -ForegroundColor Yellow
|
|
$pullResult = & $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "docker pull node:18-alpine 2>&1"
|
|
Write-Host $pullResult
|
|
|
|
if ($pullResult -match "Downloaded" -or $pullResult -match "already exists" -or $pullResult -match "Pulled") {
|
|
Write-Host "`n[SUCCESS] Docker registry is now working!" -ForegroundColor Green
|
|
Write-Host "You can now deploy your application." -ForegroundColor Green
|
|
} else {
|
|
Write-Host "`n[WARN] Image pull may have failed. Please check the output above." -ForegroundColor Yellow
|
|
Write-Host "You may need to:" -ForegroundColor Yellow
|
|
Write-Host "1. Check network connectivity on the server" -ForegroundColor White
|
|
Write-Host "2. Try using a different registry mirror" -ForegroundColor White
|
|
Write-Host "3. Use Docker Hub directly (remove registry-mirrors)" -ForegroundColor White
|
|
}
|
|
|
|
# Cleanup
|
|
Remove-Item $tempFile -Force -ErrorAction SilentlyContinue
|
|
|
|
Write-Host "`n=== Next Steps ===" -ForegroundColor Cyan
|
|
Write-Host "1. If image pull succeeded, you can now deploy:" -ForegroundColor White
|
|
Write-Host " .\scripts\deploy\deploy-simple.ps1" -ForegroundColor Green
|
|
Write-Host "`n2. If image pull failed, check the server logs:" -ForegroundColor White
|
|
Write-Host " ssh $User@$Server" -ForegroundColor Green
|
|
Write-Host " journalctl -u docker -n 50" -ForegroundColor Green
|
|
|