Last active
June 28, 2023 05:21
-
-
Save PlagueHO/d9595cae1788f436b97bd4c90d50d72e to your computer and use it in GitHub Desktop.
Install Docker on Windows Server 2016 RTM using DSC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Configuration ContainerHostDsc | |
{ | |
# Set up general parameters used to determine paths where Docker will | |
# be installed to and downloaded from. | |
$ProgramFiles = $ENV:ProgramFiles | |
$DockerPath = Join-Path -Path $ProgramFiles -ChildPath 'Docker' | |
$DockerZipFileName = 'docker.zip' | |
$DockerZipPath = Join-Path -Path $ProgramFiles -ChildPath $DockerZipFilename | |
$DockerUri = 'https://download.docker.com/components/engine/windows-server/cs-1.12/docker.zip' | |
Import-DscResource -ModuleName PSDesiredStateConfiguration | |
Import-DscResource -ModuleName xPSDesiredStateConfiguration | |
Import-DscResource -ModuleName xPendingReboot | |
Node $AllNodes.NodeName { | |
# Install containers feature | |
WindowsFeature ContainerInstall { | |
Ensure = "Present" | |
Name = "Containers" | |
} | |
# Download Docker Engine | |
xRemoteFile DockerEngineDownload { | |
DestinationPath = $ProgramFiles | |
Uri = $DockerUri | |
MatchSource = $False | |
} | |
# Extract Docker Engine zip file | |
xArchive DockerEngineExtract { | |
Destination = $ProgramFiles | |
Path = $DockerZipPath | |
Ensure = 'Present' | |
Validate = $false | |
Force = $true | |
DependsOn = '[xRemoteFile]DockerEngineDownload' | |
} | |
# Add Docker to the Path | |
xEnvironment DockerPath { | |
Ensure = 'Present' | |
Name = 'Path' | |
Value = $DockerPath | |
Path = $True | |
DependsOn = '[xArchive]DockerEngineExtract' | |
} | |
# Reboot the system to complete Containers feature setup | |
# Perform this after setting the Environment variable | |
# so that PowerShell and other consoles can access it. | |
xPendingReboot Reboot { | |
Name = "Reboot After Containers" | |
} | |
# Install the Docker Daemon as a service | |
Script DockerService { | |
SetScript = { | |
$DockerDPath = (Join-Path -Path $Using:DockerPath -ChildPath 'dockerd.exe') | |
& $DockerDPath @('--register-service') | |
} | |
GetScript = { | |
return @{ | |
'Service' = (Get-Service -Name Docker).Name | |
} | |
} | |
TestScript = { | |
if (Get-Service -Name Docker -ErrorAction SilentlyContinue) { | |
return $True | |
} | |
return $False | |
} | |
DependsOn = '[xArchive]DockerEngineExtract' | |
} | |
# Start up the Docker Service and ensure it is set | |
# to start up automatically. | |
xServiceSet DockerService { | |
Ensure = 'Present' | |
Name = 'Docker' | |
StartupType = 'Automatic' | |
State = 'Running' | |
DependsOn = '[Script]DockerService' | |
} | |
} | |
} | |
# Configure the LCM | |
Configuration ConfigureLCM { | |
Node $AllNodes.NodeName { | |
LocalConfigurationManager { | |
RebootNodeIfNeeded = $true | |
RefreshMode = 'Push' | |
ConfigurationMode = 'ApplyAndAutoCorrect' | |
ActionAfterReboot = 'ContinueConfiguration' | |
} | |
} | |
} | |
# Configuration Data | |
$ConfigData = @{ | |
AllNodes = @( | |
@{ | |
NodeName = 'localhost' | |
} | |
) | |
} | |
# Compile the LCM Config | |
ConfigureLCM ` | |
-OutputPath . ` | |
-ConfigurationData $ConfigData | |
# Apply the LCM Config | |
Set-DscLocalConfigurationManager ` | |
-Path .\ConfigureLCM\ ` | |
-ComputerName Localhost ` | |
-Verbose | |
# Compile the Node Config | |
ContainerHostDsc ` | |
-OutputPath . ` | |
-ConfigurationData $ConfigData | |
# Apply the DSC Configuration | |
Start-DscConfiguration ` | |
-Path .\ContainerHostDsc\ ` | |
-ComputerName Localhost ` | |
-Wait ` | |
-Force ` | |
-Verbose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
also need