Last active
August 24, 2026 05:56
-
-
Save CDRO/f27a168b1d3832a396a46a7edd981e87 to your computer and use it in GitHub Desktop.
Docker Related gists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| & "$PSScriptRoot\Start-DockerDesktop.ps1" | |
| function Build-Image { | |
| Write-Host "Building image..." | |
| docker build -t (Split-Path $PWD -Leaf).ToLower() . | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "Docker build failed with exit code $LASTEXITCODE" | |
| } | |
| } | |
| function Start-Container { | |
| Write-Host "Starting container..." | |
| # Adapt paths to your needs | |
| docker run -d --name (Split-Path $PWD -Leaf).ToLower() -p 5000:5000 -v "$(Get-Location)/log:/var/log/$((Split-Path $PWD -Leaf).ToLower())/" -v "$(Get-Location)/data:/app/data/" --env-file docker.env (Split-Path $PWD -Leaf).ToLower() | Out-Null | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "Docker run failed with exit code $LASTEXITCODE" | |
| } | |
| } | |
| function Stop-Container { | |
| Write-Host "Stopping container if it exists..." | |
| docker rm -f (Split-Path $PWD -Leaf).ToLower() | Out-Null | |
| } | |
| Write-Host "Press Ctrl+R to stop, remove the old container, rebuild, and restart. Press Ctrl+C to quit." | |
| while ($true) { | |
| try { | |
| Stop-Container | |
| } catch { | |
| # ignore if the container does not exist | |
| } | |
| try { | |
| Build-Image | |
| } catch { | |
| Write-Host "Build failed. Press Ctrl+R to retry." | |
| while ($true) { | |
| if ([Console]::KeyAvailable) { | |
| $key = [Console]::ReadKey($true) | |
| if ($key.Modifiers -band [ConsoleModifiers]::Control -and $key.Key -eq 'R') { | |
| break | |
| } | |
| } | |
| Start-Sleep -Milliseconds 200 | |
| } | |
| continue | |
| } | |
| try { | |
| Start-Container | |
| } catch { | |
| Write-Host "Failed to start container: $($_.Exception.Message)" | |
| Start-Sleep -Seconds 2 | |
| continue | |
| } | |
| Write-Host "Server started. Press Ctrl+R to rebuild and restart. Press Ctrl+C to quit." | |
| while ($true) { | |
| if ([Console]::KeyAvailable) { | |
| $key = [Console]::ReadKey($true) | |
| if ($key.Modifiers -band [ConsoleModifiers]::Control -and $key.Key -eq 'R') { | |
| Stop-Container | |
| break | |
| } | |
| } | |
| Start-Sleep -Milliseconds 200 | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Check if Docker Desktop is running | |
| $DockerProcess = Get-Process -Name "Docker Desktop" -ErrorAction SilentlyContinue | |
| if (-not $DockerProcess) { | |
| Write-Host "Launching Docker Desktop..." -ForegroundColor Yellow | |
| Start-Process -FilePath "C:\Program Files\Docker\Docker\Docker Desktop.exe" | |
| # Loop until 'docker ps' executes successfully without error | |
| while ($true) { | |
| & docker ps > $null 2>&1 | |
| if ($LASTEXITCODE -eq 0) { | |
| Write-Host "Docker Engine is fully ready!" -ForegroundColor Green | |
| break | |
| } | |
| Write-Host "Waiting for Docker Engine to initialize..." -ForegroundColor Cyan | |
| Start-Sleep -Seconds 3 | |
| } | |
| } else { | |
| Write-Host "Docker Desktop is already running." -ForegroundColor Green | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment