67 lines
2.4 KiB
PowerShell
67 lines
2.4 KiB
PowerShell
# 测试 Registry 连接和推送
|
||
param(
|
||
[string]$Server = "45.249.208.118",
|
||
[string]$RegistryHost = "45.249.208.118:5000"
|
||
)
|
||
|
||
Write-Host "===> 测试 Registry" -ForegroundColor Cyan
|
||
Write-Host "Registry 地址: http://$RegistryHost" -ForegroundColor Gray
|
||
Write-Host ""
|
||
|
||
# 1. 测试连接
|
||
Write-Host "1. 测试连接..." -ForegroundColor Yellow
|
||
try {
|
||
$response = Invoke-WebRequest -Uri "http://$RegistryHost/v2/" -Method GET -TimeoutSec 5 -ErrorAction Stop
|
||
Write-Host "✓ Registry 连接成功" -ForegroundColor Green
|
||
} catch {
|
||
Write-Host "✗ Registry 连接失败: $_" -ForegroundColor Red
|
||
exit 1
|
||
}
|
||
|
||
# 2. 测试推送(需要本地 Docker)
|
||
Write-Host ""
|
||
Write-Host "2. 测试推送镜像..." -ForegroundColor Yellow
|
||
|
||
# 检查 Docker
|
||
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
|
||
Write-Host "⚠ Docker 未安装,跳过推送测试" -ForegroundColor Yellow
|
||
exit 0
|
||
}
|
||
|
||
# 拉取测试镜像
|
||
Write-Host "拉取测试镜像..." -ForegroundColor Gray
|
||
docker pull hello-world:latest 2>&1 | Out-Null
|
||
|
||
# 标记镜像
|
||
$testImage = "$RegistryHost/test/hello-world:latest"
|
||
Write-Host "标记镜像: $testImage" -ForegroundColor Gray
|
||
docker tag hello-world:latest $testImage 2>&1 | Out-Null
|
||
|
||
# 推送镜像
|
||
Write-Host "推送镜像..." -ForegroundColor Gray
|
||
docker push $testImage 2>&1
|
||
if ($LASTEXITCODE -eq 0) {
|
||
Write-Host "✓ 镜像推送成功" -ForegroundColor Green
|
||
} else {
|
||
Write-Host "✗ 镜像推送失败" -ForegroundColor Red
|
||
Write-Host "提示: 请检查 Docker Desktop 是否配置了 insecure-registries" -ForegroundColor Yellow
|
||
Write-Host " Settings → Docker Engine → 添加: { `"insecure-registries`": [`"$RegistryHost`"] }" -ForegroundColor Gray
|
||
exit 1
|
||
}
|
||
|
||
# 3. 测试拉取(在服务器上)
|
||
Write-Host ""
|
||
Write-Host "3. 测试在服务器上拉取镜像..." -ForegroundColor Yellow
|
||
Write-Host "(需要手动在服务器上执行)" -ForegroundColor Gray
|
||
Write-Host " docker pull $testImage" -ForegroundColor Gray
|
||
|
||
Write-Host ""
|
||
Write-Host "===> Registry 测试完成" -ForegroundColor Green
|
||
Write-Host ""
|
||
Write-Host "Registry 信息:" -ForegroundColor Cyan
|
||
Write-Host " 地址: http://$RegistryHost" -ForegroundColor Gray
|
||
Write-Host " 镜像格式: $RegistryHost/youyidian/3d-material:latest" -ForegroundColor Gray
|
||
Write-Host ""
|
||
Write-Host "现在可以直接运行 一键镜像部署.ps1 来发布应用!" -ForegroundColor Green
|
||
|