Created
April 18, 2020 22:46
-
-
Save aadennis/55f88c2adeaaee699bef7cabb8f16253 to your computer and use it in GitHub Desktop.
This file contains 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
function Get-DockerHost() { | |
$versionOutput = $(docker version) | |
$dockerHost = $null | |
if ($versionOutput -match "linux"){ | |
$dockerHost = "Linux" | |
} else { | |
$dockerHost = "Windows" } | |
$msg = "Currently running as a [$dockerHost] host" | |
Write-Host $msg -ForegroundColor White -BackgroundColor Blue | |
return $dockerHost | |
} | |
function Switch-DockerHost() { | |
$preSwitch = Get-DockerHost | |
Write-Host "Attempting Switch from $preSwitch" | |
Start-Process "C:\Program Files\Docker\Docker\DockerCli.exe" -Wait -NoNewWindow -ArgumentList "-SwitchDaemon" | |
$postSwitch = Get-DockerHost | |
if ($preSwitch -eq $postSwitch) { | |
$msg = "Docker host failed to switch! Still set to $preSwitch" | |
Write-Host $msg -ForegroundColor Red -BackgroundColor White | |
throw $msg | |
} | |
Write-Host "Switched OK to: [$postSwitch]" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment