Containers/Start-DockerContainer.ps1
function Start-DockerContainer { Param( [Parameter(Mandatory=$true)] [string]$ContainerName ) $maxTry = 30 $tryCount = 1 $pre = $ErrorActionPreference $ErrorActionPreference = 'Continue' $tempFile = [System.IO.Path]::GetTempFileName() $start = docker start $ContainerName 2>$tempFile | Out-Null $success = $LastExitCode -eq 0 if (!$success) { $err = [System.IO.File]::ReadAllText($tempFile) if ($err.Contains('Error response from daemon: hcsshim::CreateComputeSystem')) { $ErrorActionPreference = 'Stop' do{ try{ $tryCount++ docker start $ContainerName 2>$null | Out-Null $success = $LastExitCode -eq 0 } catch { Stop-Service vmcompute } } until(($success) -or ($tryCount -eq $maxTry)) } } $ErrorActionPreference = $pre Remove-Item -Path $tempFile -ErrorAction Ignore if($success){ Write-Host "Container $ContainerName started following $tryCount attempt(s)" -ForegroundColor Green }else{ Write-Host "Container $ContainerName failed to start following $tryCount attempt(s)" -ForegroundColor Red Write-Host $err } } Export-ModuleMember -Function Start-DockerContainer |