diff --git a/helpful_tools/Install-DockerCE/README.md b/helpful_tools/Install-DockerCE/README.md index bc81424..5c70362 100644 --- a/helpful_tools/Install-DockerCE/README.md +++ b/helpful_tools/Install-DockerCE/README.md @@ -1,23 +1,15 @@ -## Install-ContainerHost.ps1 +## install-docker-ce.ps1 #### NAME - Install-ContainerHost.ps1 + install-docker-ce.ps1 #### SYNOPSIS - Installs the prerequisites for creating Windows containers + Installs the prerequisites for running Windows containers with Docker CE #### SYNTAX - Install-ContainerHost.ps1 [-DockerPath ] [-ExternalNetAdapter ] - [-Force] [-HyperV] [-NoRestart] [-PSDirect] [-SkipImageImport] - [-UseDHCP] [-WimPath ] [] - - Install-ContainerHost.ps1 [-DockerPath ] [-ExternalNetAdapter ] - [-Force] [-HyperV] [-NoRestart] [-PSDirect] - [-SkipImageImport] [-UseDHCP] [-WimPath ] [] - - Install-ContainerHost.ps1 [-DockerPath ] [-ExternalNetAdapter ] - [-Force] [-HyperV] [-NoRestart] [-PSDirect] - [-SkipImageImport] -Staging [-UseDHCP] [-WimPath ] [] + install-docker-ce.ps1 [-DockerPath ] [-DockerDPath ] [-DockerVersion ] [-ContainerBaseImage ] [-ExternalNetAdapter ] + [-Force] [-HyperV] [-SkipDefaultHost] [-NATSubnet ] [-NoRestart] [-PSDirect] [-Staging] + [-UseDHCP] [-WimPath ] [-TarPath] [] #### DESCRIPTION @@ -25,23 +17,50 @@ #### PARAMETERS - -DockerPath - Path to Docker.exe, can be local or URI + -DockerPath [] + Path to Docker.exe, can be local or URI. - Required? false + Required? True Position? named - Default value https://aka.ms/tp4/docker + Default value default + Accept pipeline input? false + Accept wildcard characters? false + + -DockerDPath [] + Path to DockerD.exe, can be local or URI. + + Required? True + Position? named + Default value default + Accept pipeline input? false + Accept wildcard characters? false + + -DockerVersion [] + The version of docker to use. + + Required? True + Position? named + Default value latest Accept pipeline input? false Accept wildcard characters? false - -ExternalNetAdapter - Specify a specific network adapter to bind to a DHCP switch + -ExternalNetAdapter [] + Specify a specific network adapter to bind to a DHCP switch. Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false + + -SkipDefaultHost [] + Prevents setting localhost as the default network configuration. + + Required? false + Position? named + Default value False + Accept pipeline input? false + Accept wildcard characters? false -Force [] If a restart is required, forces an immediate restart. @@ -60,6 +79,15 @@ Default value False Accept pipeline input? false Accept wildcard characters? false + + -NATSubnet [] + Use to override the default Docker NAT Subnet when in NAT mode. + + Required? false + Position? named + Default value + Accept pipeline input? false + Accept wildcard characters? false -NoRestart [] If a restart is required the script will terminate and will not reboot the machine @@ -70,20 +98,12 @@ Accept pipeline input? false Accept wildcard characters? false - -PSDirect [] + -ContainerBaseImage [] + Use this to specify the URI of the container base image you wish to pre-pull Required? false Position? named - Default value False - Accept pipeline input? false - Accept wildcard characters? false - - -SkipImageImport [] - Skips import of the base WindowsServerCore image. - - Required? false - Position? named - Default value False + Default value Accept pipeline input? false Accept wildcard characters? false @@ -103,8 +123,8 @@ Accept pipeline input? false Accept wildcard characters? false - -WimPath - Path to .wim file that contains the base package image + -TarPath + Path to the .tar that is the base image to load into Docker. Required? false Position? named @@ -112,12 +132,6 @@ Accept pipeline input? false Accept wildcard characters? false - - This cmdlet supports the common parameters: Verbose, Debug, - ErrorAction, ErrorVariable, WarningAction, WarningVariable, - OutBuffer, PipelineVariable, and OutVariable. For more information, see - about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). - #### NOTES Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/helpful_tools/Install-DockerCE/install-docker-ce.ps1 b/helpful_tools/Install-DockerCE/install-docker-ce.ps1 index 7760c57..ca3cb95 100644 --- a/helpful_tools/Install-DockerCE/install-docker-ce.ps1 +++ b/helpful_tools/Install-DockerCE/install-docker-ce.ps1 @@ -27,11 +27,14 @@ .PARAMETER DockerDPath Path to DockerD.exe, can be local or URI + .PARAMETER DockerVersion + Version of docker to pull from download.docker.com - ! OVERRIDDEN BY DockerPath & DockerDPath + .PARAMETER ExternalNetAdapter Specify a specific network adapter to bind to a DHCP network .PARAMETER SkipDefaultHost - Prevents setting localhost as the default n + Prevents setting localhost as the default network configuration .PARAMETER Force If a restart is required, forces an immediate restart. @@ -46,7 +49,9 @@ If a restart is required the script will terminate and will not reboot the machine .PARAMETER ContainerBaseImage - Use this to specifiy the URI of the container base image you wish to pull + Use this to specify the URI of the container base image you wish to pre-pull + + .PARAMETER Staging .PARAMETER TransparentNetwork If passed, use DHCP configuration. Otherwise, will use default docker network (NAT). (alias -UseDHCP) @@ -55,7 +60,7 @@ Path to the .tar that is the base image to load into Docker. .EXAMPLE - .\Install-ContainerHost.ps1 + .\install-docker-ce.ps1 #> #Requires -Version 5.0 @@ -64,11 +69,15 @@ param( [string] [ValidateNotNullOrEmpty()] - $DockerPath = "https://master.dockerproject.org/windows/x86_64/docker.exe", + $DockerPath = "default", [string] [ValidateNotNullOrEmpty()] - $DockerDPath = "https://master.dockerproject.org/windows/x86_64/dockerd.exe", + $DockerDPath = "default", + + [string] + [ValidateNotNullOrEmpty()] + $DockerVersion = "latest", [string] $ExternalNetAdapter, @@ -88,10 +97,6 @@ param( [switch] $NoRestart, - [Parameter(DontShow)] - [switch] - $PSDirect, - [string] $ContainerBaseImage, @@ -109,12 +114,14 @@ param( ) $global:RebootRequired = $false - $global:ErrorFile = "$pwd\Install-ContainerHost.err" - $global:BootstrapTask = "ContainerBootstrap" - $global:HyperVImage = "NanoServer" +$global:AdminPriviledges = $false + +$global:DefaultDockerLocation = "https://download.docker.com/win/static/stable/x86_64/" +$global:DockerDataPath = "$($env:ProgramData)\docker" +$global:DockerServiceName = "docker" function Restart-And-Run() @@ -393,9 +400,7 @@ Install-ContainerHost Remove-Item $global:ErrorFile Write-Output "Script complete!" -}$global:AdminPriviledges = $false -$global:DockerDataPath = "$($env:ProgramData)\docker" -$global:DockerServiceName = "docker" +} function Copy-File @@ -552,11 +557,11 @@ Install-Docker() param( [string] [ValidateNotNullOrEmpty()] - $DockerPath = "https://master.dockerproject.org/windows/x86_64/docker.exe", + $DockerPath = "default", [string] [ValidateNotNullOrEmpty()] - $DockerDPath = "https://master.dockerproject.org/windows/x86_64/dockerd.exe", + $DockerDPath = "default", [string] [ValidateNotNullOrEmpty()] @@ -571,10 +576,50 @@ Install-Docker() Test-Admin - Write-Output "Installing Docker..." + #If one of these are set to default then the whole .zip needs to be downloaded anyways. + Write-Output "DOCKER $DockerPath" + if ($DockerPath -eq "default" -or $DockerDPath -eq "default") { + Write-Output "Checking Docker versions" + #Get the list of .zip packages available from docker. + $availableVersions = ((Invoke-WebRequest -Uri $DefaultDockerLocation).Links | Where-Object {$_.href -like "docker*"}).href | Sort-Object -Descending + + #Parse the versions from the file names + $availableVersions = ($availableVersions | Select-String -Pattern "docker-(\d+\.\d+\.\d+).+" -AllMatches | Select-Object -Expand Matches | %{ $_.Groups[1].Value }) + $version = $availableVersions[0] + + if($DockerVersion -ne "latest") { + $version = $DockerVersion + if(!($availableVersions | Select-String $DockerVersion)) { + Write-Error "Docker version supplied $DockerVersion was invalid, please choose from the list of available versions: $availableVersions" + throw "Invalid docker version supplied." + } + } + + $zipUrl = $global:DefaultDockerLocation + "docker-$version.zip" + $destinationFolder = "$env:UserProfile\DockerDownloads" + + if(!(Test-Path "$destinationFolder")) { + md -Path $destinationFolder | Out-Null + } elseif(Test-Path "$destinationFolder\docker-$version") { + Remove-Item -Recurse -Force "$destinationFolder\docker-$version" + } + + Write-Output "Downloading $zipUrl to $destinationFolder\docker-$version.zip" + Copy-File -SourcePath $zipUrl -DestinationPath "$destinationFolder\docker-$version.zip" + Expand-Archive -Path "$destinationFolder\docker-$version.zip" -DestinationPath "$destinationFolder\docker-$version" + + if($DockerPath -eq "default") { + $DockerPath = "$destinationFolder\docker-$version\docker\docker.exe" + } + if($DockerDPath -eq "default") { + $DockerDPath = "$destinationFolder\docker-$version\docker\dockerd.exe" + } + } + + Write-Output "Installing Docker... $DockerPath" Copy-File -SourcePath $DockerPath -DestinationPath $env:windir\System32\docker.exe - Write-Output "Installing Docker daemon..." + Write-Output "Installing Docker daemon... $DockerDPath" Copy-File -SourcePath $DockerDPath -DestinationPath $env:windir\System32\dockerd.exe $dockerConfigPath = Join-Path $global:DockerDataPath "config"