Skip to content

Instantly share code, notes, and snippets.

@PlagueHO
Last active June 28, 2023 05:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save PlagueHO/d9595cae1788f436b97bd4c90d50d72e to your computer and use it in GitHub Desktop.
Save PlagueHO/d9595cae1788f436b97bd4c90d50d72e to your computer and use it in GitHub Desktop.
Install Docker on Windows Server 2016 RTM using DSC
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
@Lorne-LOB
Copy link

also need

Install-Module -Name xPSDesiredStateConfiguration -RequiredVersion 9.1.0
Install-Module -Name xPendingReboot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment