Skip to content

Instantly share code, notes, and snippets.

@PlagueHO
Last active June 28, 2023 05:21
Show Gist options
  • Save PlagueHO/d9595cae1788f436b97bd4c90d50d72e to your computer and use it in GitHub Desktop.
Save PlagueHO/d9595cae1788f436b97bd4c90d50d72e to your computer and use it in GitHub Desktop.

Revisions

  1. PlagueHO revised this gist Oct 16, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Install-DockerOnWS2016ByDSC.ps1
    Original file line number Diff line number Diff line change
    @@ -50,7 +50,7 @@ Configuration ContainerHostDsc
    # Perform this after setting the Environment variable
    # so that PowerShell and other consoles can access it.
    xPendingReboot Reboot {
    Name = "Reboot After Containers"
    Name = "Reboot After Containers"
    }

    # Install the Docker Daemon as a service
  2. PlagueHO revised this gist Oct 16, 2016. 1 changed file with 13 additions and 22 deletions.
    35 changes: 13 additions & 22 deletions Install-DockerOnWS2016ByDSC.ps1
    Original file line number Diff line number Diff line change
    @@ -15,23 +15,20 @@ Configuration ContainerHostDsc
    Node $AllNodes.NodeName {

    # Install containers feature
    WindowsFeature ContainerInstall
    {
    WindowsFeature ContainerInstall {
    Ensure = "Present"
    Name = "Containers"
    }

    # Download Docker Engine
    xRemoteFile DockerEngineDownload
    {
    xRemoteFile DockerEngineDownload {
    DestinationPath = $ProgramFiles
    Uri = $DockerUri
    MatchSource = $False
    }

    # Extract Docker Engine zip file
    xArchive DockerEngineExtract
    {
    xArchive DockerEngineExtract {
    Destination = $ProgramFiles
    Path = $DockerZipPath
    Ensure = 'Present'
    @@ -41,26 +38,23 @@ Configuration ContainerHostDsc
    }

    # Add Docker to the Path
    xEnvironment DockerPath
    {
    xEnvironment DockerPath {
    Ensure = 'Present'
    Name = 'Path'
    Value = $DockerPath
    Path = $True
    DependsOn = '[xArchive]DockerEngineExtract'
    }

    # Reboot the system to complete Containers feature setup
    # 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"
    }
    xPendingReboot Reboot {
    Name = "Reboot After Containers"
    }

    # Install the Docker Daemon as a service
    Script DockerService
    {
    Script DockerService {
    SetScript = {
    $DockerDPath = (Join-Path -Path $Using:DockerPath -ChildPath 'dockerd.exe')
    & $DockerDPath @('--register-service')
    @@ -81,8 +75,7 @@ Configuration ContainerHostDsc

    # Start up the Docker Service and ensure it is set
    # to start up automatically.
    xServiceSet DockerService
    {
    xServiceSet DockerService {
    Ensure = 'Present'
    Name = 'Docker'
    StartupType = 'Automatic'
    @@ -93,15 +86,13 @@ Configuration ContainerHostDsc
    }

    # Configure the LCM
    Configuration ConfigureLCM
    {
    Configuration ConfigureLCM {
    Node $AllNodes.NodeName {
    LocalConfigurationManager
    {
    LocalConfigurationManager {
    RebootNodeIfNeeded = $true
    RefreshMode = 'Push'
    ConfigurationMode = 'ApplyAndAutoCorrect'
    ActionAfterReboot = 'ContinueConfiguration'
    ActionAfterReboot = 'ContinueConfiguration'
    }
    }
    }
  3. PlagueHO created this gist Oct 15, 2016.
    140 changes: 140 additions & 0 deletions Install-DockerOnWS2016ByDSC.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,140 @@
    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