Skip to content

Instantly share code, notes, and snippets.

@aadennis
Created April 18, 2020 22:46
Show Gist options
  • Save aadennis/55f88c2adeaaee699bef7cabb8f16253 to your computer and use it in GitHub Desktop.
Save aadennis/55f88c2adeaaee699bef7cabb8f16253 to your computer and use it in GitHub Desktop.
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