-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_docker.ps1
44 lines (38 loc) · 1.79 KB
/
install_docker.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Install Windows feature containers
$restartNeeded = $false
if (!(Get-WindowsOptionalFeature -FeatureName containers -Online).State -eq 'Enabled') {
$restartNeeded = (Enable-WindowsOptionalFeature -FeatureName containers -Online).RestartNeeded
}
if (Get-Service docker -ErrorAction SilentlyContinue)
{
Stop-Service docker
}
# Download the zip file.
$json = Invoke-WebRequest https://download.docker.com/components/engine/windows-server/index.json | ConvertFrom-Json
$version = $version = $json.channels.'18.09'.version
$url = $json.versions.$version.url
$zipfile = Join-Path "$env:USERPROFILE\Downloads\" $json.versions.$version.url.Split('/')[-1]
Invoke-WebRequest -UseBasicparsing -Outfile $zipfile -Uri $url
# Extract the archive.
Expand-Archive $zipfile -DestinationPath $Env:ProgramFiles -Force
# Modify PATH to persist across sessions.
$newPath = [Environment]::GetEnvironmentVariable("PATH",[EnvironmentVariableTarget]::Machine) + ";$env:ProgramFiles\docker"
$splittedPath = $newPath -split ';'
$cleanedPath = $splittedPath | Sort-Object -Unique
$newPath = $cleanedPath -join ';'
[Environment]::SetEnvironmentVariable("PATH", $newPath, [EnvironmentVariableTarget]::Machine)
$env:path = $newPath
# Register the Docker daemon as a service.
if (!(Get-Service docker -ErrorAction SilentlyContinue)) {
dockerd --exec-opt isolation=process --register-service
}
# Start the Docker service.
if ($restartNeeded) {
Write-Host 'A restart is needed to finish the installation' -ForegroundColor Green
If ((Read-Host 'Do you want to restart now? [Y/N]') -eq 'Y') {
Restart-Computer
}
} else {
Start-Service docker
}
Invoke-WebRequest "https://github.com/docker/compose/releases/download/1.12.0/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFiles\docker\docker-compose.exe