Skip to content

Instantly share code, notes, and snippets.

@NielsPilgaard
Created October 16, 2019 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NielsPilgaard/373e73ef8aa63451eaa728a57a495af6 to your computer and use it in GitHub Desktop.
Save NielsPilgaard/373e73ef8aa63451eaa728a57a495af6 to your computer and use it in GitHub Desktop.
$DockerPath = "$env:ProgramFiles\Docker"
function Install-Docker {
Invoke-WebRequest "https://master.dockerproject.org/windows/x86_64/docker.zip" -OutFile "$env:TEMP\docker.zip" -UseBasicParsing
Expand-Archive -Path "$env:TEMP\docker.zip" -DestinationPath $env:ProgramFiles
$env:path += ";$env:ProgramFiles\Docker"
$Path = [Environment]::GetEnvironmentVariable("Path",[System.EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable("Path", $Path + ";$env:ProgramFiles\Docker", [EnvironmentVariableTarget]::Machine)
Confirm-ContainerType
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Enable-WindowsOptionalFeature -Online -FeatureName Containers -All
}
function Confirm-ContainerType {
param (
[Parameter(Mandatory=$true)]
[ValidateSet("windows","linux")]
[string]
$TargetDaemon
)
$Daemon = "*"+$TargetDaemon.ToLower()+"*";
$DockerVersion = Docker version | Select-Object -Last 2
if ($DockerVersion -like $Daemon)
{
Write-Host "Daemon already set to:"$TargetDaemon
}
else
{
Write-Host "Switching Daemon to $TargetDaemon..."
& "$Env:ProgramFiles\Docker\Docker\DockerCli.exe" -SwitchDaemon
Write-Host "Daemon switched!"
}
}
function Show-Menu {
Write-Host "=========================================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "This Project requires Docker." -ForegroundColor Cyan
Write-Host ""
Write-Host "=========================================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "You have the following options:" -ForegroundColor Cyan
Write-Host ""
Write-Host "e: Install Docker" -ForegroundColor Cyan
Write-Host ""
Write-Host "Warning: This will require a PC restart after completion." -ForegroundColor Red
Write-Host "Hyper-V and Containers will be enabled on your PC." -ForegroundColor Red
Write-Host ""
Write-Host "q: Quit" -ForegroundColor Cyan
Write-Host ""
}
Set-Location $PSScriptRoot
if (Test-Path $DockerPath)
{
Write-Host "Docker has been detected." -ForegroundColor Cyan
Write-Host ""
Write-Host "Do you wish to run the TestManager?" -ForegroundColor Cyan
Write-Host ""
Write-Host "Warning: This can take a very long time on the first run." -ForegroundColor Red
Write-Host ""
Write-Host "Quit with CTRL+C" -ForegroundColor Red
pause
Start-Sleep 1
Clear-Host
& "$Env:ProgramFiles\Docker\Docker\Docker for Windows.exe" -Verb RunAs
while (!(Get-Process "Docker for Windows" -ErrorAction SilentlyContinue)) {
Write-Host "Starting Docker Daemon..."
}
Write-Host "Daemon is running."
Write-Host "Waiting for Docker to initialize..."
Start-Sleep 25
# Clear-Host
# docker-compose up --build
}
else
{
Show-Menu
$input = Read-Host "Choose an action"
switch ($input)
{
"e"
{
Clear-Host
Write-Host "You chose Install Docker."
Write-Host ""
Write-Host "It is recommended that you disable running Docker on startup."
Write-Host "Set Docker to use Windows Containers, if it is set to Linux Containers."
Write-Host "The Docker settings can be accessed from the system tray."
pause
Install-Docker
}
"q"
{
Clear-Host
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment