Merge pull request #331 from microsoft/docker-ce-update

Added logic to download and extract docker from download.docker.com. …
This commit is contained in:
Brandon Smith 2023-03-21 13:05:45 -07:00 коммит произвёл GitHub
Родитель 944de143bd 1cd120576c
Коммит 5ee40e8be8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 117 добавлений и 58 удалений

Просмотреть файл

@ -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 <String>] [-ExternalNetAdapter <String>]
[-Force] [-HyperV] [-NoRestart] [-PSDirect] [-SkipImageImport]
[-UseDHCP] [-WimPath <String>] [<CommonParameters>]
Install-ContainerHost.ps1 [-DockerPath <String>] [-ExternalNetAdapter <String>]
[-Force] [-HyperV] [-NoRestart] [-PSDirect]
[-SkipImageImport] [-UseDHCP] [-WimPath <String>] [<CommonParameters>]
Install-ContainerHost.ps1 [-DockerPath <String>] [-ExternalNetAdapter <String>]
[-Force] [-HyperV] [-NoRestart] [-PSDirect]
[-SkipImageImport] -Staging [-UseDHCP] [-WimPath <String>] [<CommonParameters>]
install-docker-ce.ps1 [-DockerPath <String>] [-DockerDPath <String>] [-DockerVersion <String>] [-ContainerBaseImage <String>] [-ExternalNetAdapter <String>]
[-Force] [-HyperV] [-SkipDefaultHost] [-NATSubnet <String>] [-NoRestart] [-PSDirect] [-Staging]
[-UseDHCP] [-WimPath <String>] [-TarPath] [<CommonParameters>]
#### DESCRIPTION
@ -25,23 +17,50 @@
#### PARAMETERS
-DockerPath <String>
Path to Docker.exe, can be local or URI
-DockerPath [<String>]
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 [<String>]
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 [<String>]
The version of docker to use.
Required? True
Position? named
Default value latest
Accept pipeline input? false
Accept wildcard characters? false
-ExternalNetAdapter <String>
Specify a specific network adapter to bind to a DHCP switch
-ExternalNetAdapter [<String>]
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 [<SwitchParameter>]
Prevents setting localhost as the default network configuration.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-Force [<SwitchParameter>]
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 [<String>]
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 [<SwitchParameter>]
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 [<SwitchParameter>]
-ContainerBaseImage [<String>]
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 [<SwitchParameter>]
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 <String>
Path to .wim file that contains the base package image
-TarPath <String>
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
<CommonParameters>
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.

Просмотреть файл

@ -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"