flnxi-Wu/scripts/deploy/check-docker-images.ps1
WuYongJie f646b71813
Some checks failed
CI Check / check (push) Has been cancelled
chore: 初始化本地仓库并同步最近改动
2025-11-18 17:50:16 +08:00

63 lines
3.2 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 检查服务器上的 Docker 镜像状态
param(
[string]$Server = "45.249.208.118",
[string]$User = "root",
[string]$Password = "lxvhNYFZ4160"
)
$ErrorActionPreference = "Stop"
Write-Host "检查服务器上的 Docker 镜像状态..." -ForegroundColor Cyan
$plinkPath = "C:\Program Files\PuTTY\plink.exe"
if (-not (Test-Path $plinkPath)) {
Write-Host "错误: 未找到 plink.exe" -ForegroundColor Red
Write-Host "请安装 PuTTY 或使用 ssh 命令" -ForegroundColor Yellow
exit 1
}
Write-Host "`n[1/4] 检查 Docker 是否运行..." -ForegroundColor Yellow
$dockerStatus = & $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "docker --version 2>&1"
Write-Host $dockerStatus -ForegroundColor Green
Write-Host "`n[2/4] 检查本地镜像(node:18-alpine)..." -ForegroundColor Yellow
$nodeImages = & $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "docker images node:18-alpine 2>&1"
Write-Host $nodeImages -ForegroundColor Cyan
if ($nodeImages -match "node.*18-alpine") {
Write-Host "`n✅ 服务器上已有 node:18-alpine 镜像" -ForegroundColor Green
Write-Host " 无需从镜像仓库拉取,可以直接构建" -ForegroundColor Green
} else {
Write-Host "`n❌ 服务器上未找到 node:18-alpine 镜像" -ForegroundColor Red
Write-Host " 需要从镜像仓库拉取,但当前镜像源可能有问题" -ForegroundColor Yellow
}
Write-Host "`n[3/4] 检查 Docker 镜像源配置..." -ForegroundColor Yellow
$daemonConfig = & $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "cat /etc/docker/daemon.json 2>&1"
if ($daemonConfig -match "registry-mirrors") {
Write-Host $daemonConfig -ForegroundColor Cyan
} else {
Write-Host "未找到 daemon.json 或未配置镜像源" -ForegroundColor Yellow
Write-Host "(可能使用默认 Docker Hub 或 1Panel 配置)" -ForegroundColor Yellow
}
Write-Host "`n[4/4] 测试镜像拉取(仅测试,不实际拉取)..." -ForegroundColor Yellow
Write-Host "测试连接到 docker.1panel.live..." -ForegroundColor Cyan
$testConnection = & $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "curl -I https://docker.1panel.live/v2/ 2>&1 | head -1"
Write-Host $testConnection -ForegroundColor Cyan
Write-Host "`n=== 诊断结果 ===" -ForegroundColor Cyan
Write-Host "1. 如果服务器上已有 node:18-alpine 镜像:" -ForegroundColor White
Write-Host " → 可以直接执行 docker compose up -d --build" -ForegroundColor Green
Write-Host " → 无需从镜像仓库拉取" -ForegroundColor Green
Write-Host "`n2. 如果服务器上未找到镜像:" -ForegroundColor White
Write-Host " → 需要修复 Docker 镜像源配置" -ForegroundColor Yellow
Write-Host " → 或使用其他镜像源(如 Docker Hub 官方源)" -ForegroundColor Yellow
Write-Host " → 或从本地导出镜像并上传到服务器" -ForegroundColor Yellow
Write-Host "`n建议操作:" -ForegroundColor Cyan
Write-Host "1. 检查服务器上是否已有镜像(见上方输出)" -ForegroundColor White
Write-Host "2. 如果有镜像,直接部署即可" -ForegroundColor White
Write-Host "3. 如果没有镜像,参考 Docker镜像更新说明.md 中的解决方案" -ForegroundColor White