93 lines
4.9 KiB
PowerShell
93 lines
4.9 KiB
PowerShell
# Manual image import guide and script
|
|
param(
|
|
[string]$Server = "45.249.208.118",
|
|
[string]$User = "root",
|
|
[string]$Password = "lxvhNYFZ4160"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
Write-Host "Checking server for existing images and alternative solutions..." -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/4] Checking existing Docker images on server..." -ForegroundColor Yellow
|
|
$allImages = & $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "docker images --format '{{.Repository}}:{{.Tag}}' 2>&1"
|
|
Write-Host $allImages
|
|
|
|
Write-Host "`n[2/4] Checking if node images exist..." -ForegroundColor Yellow
|
|
$nodeImages = & $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "docker images node --format '{{.Repository}}:{{.Tag}}' 2>&1"
|
|
Write-Host $nodeImages
|
|
|
|
if ($nodeImages -match "node.*18") {
|
|
Write-Host "`n[INFO] Found Node.js image on server" -ForegroundColor Green
|
|
Write-Host "You can use existing image or tag it as node:18-alpine" -ForegroundColor Cyan
|
|
}
|
|
|
|
Write-Host "`n[3/4] Checking Docker build cache..." -ForegroundColor Yellow
|
|
$buildCache = & $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "docker system df -v 2>&1 | head -20"
|
|
Write-Host $buildCache
|
|
|
|
Write-Host "`n[4/4] Checking if we can build from scratch..." -ForegroundColor Yellow
|
|
Write-Host "Since server cannot pull images, let's check if we can use a local base or build directly" -ForegroundColor Cyan
|
|
|
|
# Check if there's a way to get the image
|
|
Write-Host "`n=== Solutions ===" -ForegroundColor Cyan
|
|
|
|
Write-Host "`nSolution 1: Use existing image (if available)" -ForegroundColor Yellow
|
|
Write-Host "If server has any node image, we can tag it:" -ForegroundColor White
|
|
Write-Host " ssh $User@$Server" -ForegroundColor Green
|
|
Write-Host " docker tag <existing-node-image> node:18-alpine" -ForegroundColor Green
|
|
|
|
Write-Host "`nSolution 2: Download image file manually and import" -ForegroundColor Yellow
|
|
Write-Host "1. Download node:18-alpine from a machine with internet access:" -ForegroundColor White
|
|
Write-Host " docker pull node:18-alpine" -ForegroundColor Green
|
|
Write-Host " docker save node:18-alpine -o node-18-alpine.tar" -ForegroundColor Green
|
|
Write-Host " gzip node-18-alpine.tar" -ForegroundColor Green
|
|
Write-Host "2. Upload to server:" -ForegroundColor White
|
|
Write-Host " scp node-18-alpine.tar.gz $User@${Server}:/tmp/" -ForegroundColor Green
|
|
Write-Host "3. Import on server:" -ForegroundColor White
|
|
Write-Host " ssh $User@$Server" -ForegroundColor Green
|
|
Write-Host " gunzip -c /tmp/node-18-alpine.tar.gz | docker load" -ForegroundColor Green
|
|
|
|
Write-Host "`nSolution 3: Modify Dockerfile to use a different base (if available locally)" -ForegroundColor Yellow
|
|
Write-Host "Check what base images are available on server" -ForegroundColor White
|
|
|
|
Write-Host "`nSolution 4: Build without pulling (if base layer exists in cache)" -ForegroundColor Yellow
|
|
Write-Host "Try building directly - Docker might use cached layers:" -ForegroundColor White
|
|
Write-Host " ssh $User@$Server" -ForegroundColor Green
|
|
Write-Host " cd /root/youyidian-3d" -ForegroundColor Green
|
|
Write-Host " docker compose build --no-cache" -ForegroundColor Green
|
|
Write-Host " # This will fail if base image doesn't exist, but worth trying" -ForegroundColor Gray
|
|
|
|
Write-Host "`n=== Recommended Action ===" -ForegroundColor Cyan
|
|
Write-Host "Since server cannot access external Docker registries, the best solution is:" -ForegroundColor Yellow
|
|
Write-Host "1. Find a machine with Docker and internet access" -ForegroundColor White
|
|
Write-Host "2. Export the node:18-alpine image" -ForegroundColor White
|
|
Write-Host "3. Upload to server and import" -ForegroundColor White
|
|
Write-Host "`nOr contact server administrator to:" -ForegroundColor Yellow
|
|
Write-Host "- Open firewall for Docker Hub access" -ForegroundColor White
|
|
Write-Host "- Configure a proxy server" -ForegroundColor White
|
|
Write-Host "- Provide access to an internal Docker registry" -ForegroundColor White
|
|
|
|
# Check if we can at least try to build
|
|
Write-Host "`n=== Trying Alternative: Check if build works with existing cache ===" -ForegroundColor Cyan
|
|
Write-Host "Attempting to check build context..." -ForegroundColor Yellow
|
|
|
|
$projectPath = "/root/youyidian-3d"
|
|
$dockerfileExists = & $plinkPath -ssh -pw $Password -batch "${User}@${Server}" "test -f $projectPath/Dockerfile && echo 'exists' || echo 'not found'"
|
|
Write-Host "Dockerfile exists: $dockerfileExists" -ForegroundColor Cyan
|
|
|
|
if ($dockerfileExists -match "exists") {
|
|
Write-Host "`nYou can try building directly (may use cached layers):" -ForegroundColor Yellow
|
|
Write-Host " ssh $User@$Server" -ForegroundColor Green
|
|
Write-Host " cd $projectPath" -ForegroundColor Green
|
|
Write-Host " docker compose build 2>&1 | tee build.log" -ForegroundColor Green
|
|
Write-Host "`nIf it fails due to missing base image, you'll need to import it manually." -ForegroundColor Yellow
|
|
}
|
|
|