DSC Class Based resource to create Windows Containers
PowerShell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Configuration.ps1
GetDSCConfigIPandID.jpg
LICENSE
README.md
cWindowsContainer.psd1
cWindowsContainer.psm1
newcontainerconfig.jpg

README.md

cWindowsContainer

Class Based DSC resource to deploy Windows Containers.

Update Sep 2015 Get-DscConfiguration now shows ContainerId and currently assigned IP Address Config Update Dec 2015 Resource updated for TP4 (TP3 must use version 1.0). Now supports HyperV container type and the defining of the hostname within the container. Validated Nano Server compatibility Added SharedFolder possibility

Deploy container from Nano image with single line startup script

configuration NewContainer {
    Import-DscResource -ModuleName cWindowsContainer -ModuleVersion 1.1

    cWindowsContainer MyAppContainer {
        Ensure = 'Present'
        Name = 'MyAppContainer'
        StartUpScript = '"Hello World" | out-file c:\hello.txt'
        ContainerImageName = 'NanoServer'
    }
}
NewContainer
Start-DscConfiguration .\NewContainer -Wait -Verbose

Config

Deploy container from Nano image with multi-line startup script and specifying Container Hostname

configuration MultiLineConfigContainer {
    param (
        [String] $StartupScript
    )
    Import-DscResource -ModuleName cWindowsContainer -ModuleVersion 1.1

    cWindowsContainer MyDCContainer {
        Ensure = 'Present'
        Name = 'MyDCContainer'
        StartUpScript = $StartupScript
        ContainerImageName = 'NanoServer'
        ContainerType = 'HyperV'
        ContainerComputerName = 'MyContainer'
    }
}

$script = @'
$computername = $env:COMPUTERNAME
$computername.tolower() | out-file c:\compname.txt
'@

MultiLineConfigContainer -StartupScript $script
Start-DscConfiguration .\MultiLineConfigContainer -Wait -Verbose
```

**Remove container**
```powershell
configuration RemContainer {
    Import-DscResource -ModuleName cWindowsContainer -ModuleVersion 1.1

    cWindowsContainer MyAppContainer {
        Ensure = 'Absent'
        Name = 'MyAppContainer'
        ContainerImageName = 'NanoServer'
    }
}
RemContainer
Start-DscConfiguration .\RemContainer -Wait -Verbose
```
**NGINX install and Network (does not work on Nano as Invoke-WebRequest is not available)**
```powershell
configuration ContainerNginX {
    param (
        [String] $StartupScript
    )
    Import-DscResource -ModuleName cWindowsContainer -ModuleVersion 1.1

    cWindowsContainer NginX {
        Ensure = 'Present'
        Name = 'NginX'
        StartUpScript = $StartupScript
        SwitchName = 'Virtual Switch'
        ContainerImageName = 'WindowsServerCore'
		SourcePath = 'C:\Share\www'
		DestinationPath = 'C:\nginx-1.9.4\html'
		AccessMode = 'ReadOnly'
    }
}

$script = @'
Invoke-WebRequest -Uri 'http://nginx.org/download/nginx-1.9.4.zip' -OutFile 'c:\nginx-1.9.4.zip'
Unblock-File -Path 'c:\nginx-1.9.4.zip'
Expand-Archive -Path 'c:\nginx-1.9.4.zip' -DestinationPath C:\ -Force
Set-Location -Path C:\nginx-1.9.4
Start-Process nginx
'@

ContainerNginX -StartupScript $script
Start-DscConfiguration .\ContainerNginX -Wait -Verbose -Force
```