Last active
November 12, 2016 21:14
-
-
Save bgelens/152fdc075b6ffcf639da775958076c6a to your computer and use it in GitHub Desktop.
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
Install-Module -Name xPSDesiredStateConfiguration -Force | |
[DscLocalConfigurationManager()] | |
configuration LCM { | |
Settings { | |
RebootNodeIfNeeded = $true | |
ActionAfterReboot = 'ContinueConfiguration' | |
} | |
} | |
configuration Win10ContainerHost { | |
Import-DscResource -ModuleName PSDesiredStateConfiguration | |
Import-DscResource -ModuleName xPSDesiredStateConfiguration | |
node localhost { | |
WindowsOptionalFeature HyperV { | |
Ensure = 'Enable' | |
Name = 'Microsoft-Hyper-V-All' | |
} | |
WindowsOptionalFeature Containers { | |
Ensure = 'Enable' | |
Name = 'Containers' | |
} | |
xRemoteFile DockerD { | |
DestinationPath = 'C:\Program Files\docker\dockerd.exe' | |
Uri = 'https://master.dockerproject.org/windows/amd64/dockerd.exe' | |
} | |
xRemoteFile DockerClient { | |
DestinationPath = 'C:\Program Files\docker\docker.exe' | |
Uri = 'https://master.dockerproject.org/windows/amd64/docker.exe' | |
} | |
Environment DockerEnv { | |
Path = $true | |
Name = 'Path' | |
Value = 'C:\Program Files\docker\' | |
} | |
script EnableDockerService { | |
GetScript = { | |
$result = if (Get-Service -Name Docker -ErrorAction SilentlyContinue) {'Service Present'} else {'Service Absent'} | |
return @{ | |
GetScript = $GetScript | |
SetScript = $SetScript | |
TestScript = $TestScript | |
Result = $Result | |
} | |
} | |
SetScript = { | |
& 'C:\Program Files\docker\dockerd.exe' --register-service | |
} | |
TestScript = { | |
if (Get-Service -Name Docker -ErrorAction SilentlyContinue) { | |
return $true | |
} else { | |
return $false | |
} | |
} | |
DependsOn = '[xRemoteFile]DockerD' | |
} | |
service DockerD { | |
Name = 'Docker' | |
State = 'Running' | |
DependsOn = '[Script]EnableDockerService' | |
} | |
Registry VSmbDisableOplocks { | |
Ensure = 'Present' | |
Key = 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization\Containers' | |
ValueName = 'VSmbDisableOplocks' | |
ValueData = 1 | |
ValueType = 'Dword' | |
} | |
} | |
} | |
LCM | |
Set-DscLocalConfigurationManager -Path .\LCM -Verbose | |
Win10ContainerHost | |
Start-DscConfiguration .\Win10ContainerHost -Wait -Verbose -Force |
Awesome script - I actually did a search for DSC for containers on Windows Server 2016 - but didn't think to include Windows 10! Doh! Finding this would have actually saved me a lot of effort! Doh!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
xRemoteFile downloads every time Start-DscConfiguration is used. This will throw an exception when the docker daemon is already active and xRemoteFile cannot overwrite the executable. If you want to rerun the configuration, stop the docker service first to avoid terminating exception.