|
21 | 21 | - name: Checkout |
22 | 22 | uses: actions/checkout@v4 |
23 | 23 |
|
24 | | - - name: Show Docker info |
| 24 | + - name: Ensure Docker daemon is running |
| 25 | + shell: pwsh |
| 26 | + working-directory: . |
25 | 27 | run: | |
| 28 | + # Workaround for actions/runner-images#13729: |
| 29 | + # On Windows runners the docker service is sometimes left in the Stopped |
| 30 | + # state at job start because the Hyper-V virtual switch fails to |
| 31 | + # initialise during the runner's resume from a saved image. Starting |
| 32 | + # the service (with retries) recovers the daemon. |
| 33 | + $ErrorActionPreference = 'Continue' |
| 34 | +
|
| 35 | + $ready = $false |
| 36 | + for ($attempt = 1; $attempt -le 5; $attempt++) { |
| 37 | + $svc = Get-Service -Name docker -ErrorAction SilentlyContinue |
| 38 | + if (-not $svc) { |
| 39 | + throw "docker service is not installed on this runner." |
| 40 | + } |
| 41 | + Write-Host "Attempt $attempt: docker service status is $($svc.Status)" |
| 42 | + if ($svc.Status -ne 'Running') { |
| 43 | + Start-Service -Name docker -ErrorAction SilentlyContinue |
| 44 | + Start-Sleep -Seconds 3 |
| 45 | + } |
| 46 | +
|
| 47 | + $deadline = (Get-Date).AddSeconds(60) |
| 48 | + while ((Get-Date) -lt $deadline) { |
| 49 | + docker version --format '{{.Server.Version}}' *> $null |
| 50 | + if ($LASTEXITCODE -eq 0) { $ready = $true; break } |
| 51 | + Start-Sleep -Seconds 2 |
| 52 | + } |
| 53 | +
|
| 54 | + if ($ready) { |
| 55 | + Write-Host "Docker daemon is responsive." |
| 56 | + break |
| 57 | + } |
| 58 | +
|
| 59 | + Write-Host "Daemon did not respond on attempt $attempt; restarting service." |
| 60 | + Stop-Service -Name docker -Force -ErrorAction SilentlyContinue |
| 61 | + Start-Sleep -Seconds 2 |
| 62 | + } |
| 63 | +
|
| 64 | + if (-not $ready) { |
| 65 | + Write-Host "::group::Docker service state" |
| 66 | + Get-Service -Name docker | Format-List * |
| 67 | + Write-Host "::endgroup::" |
| 68 | + Write-Host "::group::Recent Application event log (docker)" |
| 69 | + Get-EventLog -LogName Application -Source docker -Newest 20 -ErrorAction SilentlyContinue | |
| 70 | + Format-List TimeGenerated, EntryType, Message |
| 71 | + Write-Host "::endgroup::" |
| 72 | + throw "Docker daemon did not become ready after 5 attempts." |
| 73 | + } |
| 74 | +
|
26 | 75 | docker version |
27 | 76 | docker info |
28 | 77 |
|
|
0 commit comments