|
1 | 1 | # A powershell script for Windows to check if any desktop container runtime is available and running |
2 | 2 |
|
| 3 | +function Write-ContainerRuntimeInstructions { |
| 4 | + Write-Host "To install a container runtime, please visit the following links:" |
| 5 | + Write-Host "- Docker Desktop: https://www.docker.com/products/docker-desktop" |
| 6 | + Write-Host "- Podman Desktop: https://podman-desktop.io/" |
| 7 | + Write-Host "Please install one of these runtimes and try again." |
| 8 | +} |
| 9 | + |
3 | 10 | # Check if Docker Desktop is running |
| 11 | +$dockerAvailable = $false |
| 12 | +$dockerRunning = $false |
4 | 13 | if (Get-Command "docker" -ErrorAction SilentlyContinue) { |
5 | | - $dockerStatus = & docker info --format '{{.ServerVersion}}' |
| 14 | + $dockerAvailable = $true |
| 15 | + $dockerStatus = & docker info --format '{{.ServerVersion}}' 2>$null |
6 | 16 | if ($dockerStatus) { |
7 | 17 | Write-Host "Docker Desktop is running." |
8 | 18 | exit 0 |
9 | 19 | } else { |
10 | 20 | Write-Host "Docker Desktop is not running." |
11 | | - exit 1 |
12 | 21 | } |
13 | 22 | } |
14 | 23 |
|
15 | 24 | # Check if Podman Desktop is running |
| 25 | +$podmanAvailable = $false |
| 26 | +$podmanRunning = $false |
16 | 27 | if (Get-Command "podman" -ErrorAction SilentlyContinue) { |
17 | | - $podmanStatus = & podman info --format '{{.ServerVersion}}' |
| 28 | + $podmanAvailable = $true |
| 29 | + $podmanStatus = & podman info --format '{{.ServerVersion}}' 2>$null |
18 | 30 | if ($podmanStatus) { |
19 | 31 | Write-Host "Podman Desktop is running." |
20 | 32 | exit 0 |
21 | 33 | } else { |
22 | 34 | Write-Host "Podman Desktop is not running." |
23 | | - exit 1 |
24 | 35 | } |
25 | 36 | } |
| 37 | + |
| 38 | +if (-not $dockerAvailable -and -not $podmanAvailable) { |
| 39 | + Write-Error "The `docker` and `podman` commands are not available" |
| 40 | + Write-ContainerRuntimeInstructions |
| 41 | + exit 1 |
| 42 | +} |
| 43 | + |
| 44 | +Write-Error "No container runtime is running." |
| 45 | +Write-ContainerRuntimeInstructions |
| 46 | +exit 1 |
0 commit comments