Build your image by committing images - artisticcheese/artisticcheesecontainer GitHub Wiki

##Building images by committing existing image One of the options of creating docker images is committing running image after making manual changes to it. This is not recommended option neither by docker or Microsoft because it prevents any sort of automated builds but it's still possible to do and provide certain advantages.
One of common uses for this setup is patching systems. You can just apply patch to running container, commit the image, slap latest tag on it and start your application again and it will be running patched container.
If you use dockerfile builds technique instead then you have to rebuild all your layers from ground up when new base/patched image from Microsoft is released which is cleaner and automatable solution but have a drawback or redoing all the layers on each patching cycle.
Steps for committing image (same steps will be taken in next article using dockerfile instead)

  • Launch docker container off microsoft\iis base image
Run-ContainerImage -ImageIdOrName "artisticcheese/base:latest" -Detach -Name iis
  • Login into running container using ISE (important to use ISE since we are going to edit files)
PS C:\WINDOWS\system32> Enter-PSSession -ContainerId (Get-Container iis).ID -RunAsAdministrator
  • Create and start editing file start.ps1
New-Item -Type File -path start.ps1
psedit start.ps1
  • Paste following DSC statement in ISE edit window and save it. (This saves file into container, which is awesome feature of ISE)
Configuration BasicIIS
{
   Import-DscResource -ModuleName 'PSDesiredStateConfiguration' 
   node localhost {
         WindowsFeature IIS
        {
            Ensure = "Present"
            Name = "Web-Mgmt-Service"
        }
        WindowsFeature HTTPWCF
        {
            Ensure = "Present"
            Name = "net-wcf-http-Activation45"
        } 
         WindowsFeature Web-Http-Tracing
        {
            Ensure = "Present"
            Name = "Web-Http-Tracing"
        } 
         WindowsFeature Web-Request-Monitor
        {
            Ensure = "Present"
            Name = "Web-Request-Monitor"
        } 
        Service WebManagementService
        {    
            Name = "WMSVC"
            StartupType = "Automatic"
            State = "Running"
            DependsOn = "[WindowsFeature]IIS"
        }
        Registry RemoteManagement
        {
            Key = "HKLM:\SOFTWARE\Microsoft\WebManagement\Server"
            ValueName =  "EnableRemoteManagement"
            ValueData = 1
            ValueType = "Dword"
            DependsOn = "[WindowsFeature]IIS"
        }
        Script NugetPackageProvider   
        {
            SetScript = {Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force}
            TestScript =  {if ((Get-PackageProvider -listavailable -name nuget -erroraction SilentlyContinue).Count -eq 0) {return $false} else {return $true}}
            GetScript = {@{Result = "true"}}       
        }
        Script ChocolateyPackageProvider   
        {
            SetScript = {Register-PackageSource -Name chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/ -force}
            TestScript =  {if ((Get-PackageProvider -listavailable -name Chocolatey -erroraction SilentlyContinue).Count -eq 0) {return $false} else {return $true}}
            GetScript = {@{Result = "true"}}       
        }
        Script xWebAdministration
        { 
            SetScript = {Install-Module xWebAdministration}
            TestScript =  {if ((get-module xwebadminstration -ListAvailable).Count -eq 0){return $false}else {return $true}}
            GetScript = {@{Result = "true"}}
            DependsOn = "[Script]NugetPackageProvider"
        }
        WindowsFeature WindowsDefenderFeatures
        {
            Ensure = "Absent"
            Name = "Windows-Defender-Features"
            IncludeAllSubFeature = $true
        }
        File IISLogFolder
        {
            Type = 'Directory'
            DestinationPath = 'c:\logs'
            Ensure = 'Present'
        }

    }
}

BasicIIS -OutputPath .\BasicIIS
Start-DscConfiguration -Wait -Verbose -Path .\BasicIIS -Force
  • Execute your script
[a3cf5b7bb54e...]: PS C:\inetpub\wwwroot> .\start.ps1


    Directory: C:\inetpub\wwwroot\BasicIIS


Mode                LastWriteTime         Length Name                                                                                                                                                                                                                 
----                -------------         ------ ----                                                                                                                                                                                                                 
-a----        1/23/2017  12:23 PM          10838 localhost.mof                                                                                                                                                                                                        
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer A3CF5B7BB54E with user sid S-1-5-93-2-1.
VERBOSE: [A3CF5B7BB54E]: LCM:  [ Start  Set      ]
VERBOSE: [A3CF5B7BB54E]: LCM:  [ Start  Resource ]  [[WindowsFeature]IIS]
VERBOSE: [A3CF5B7BB54E]: LCM:  [ Start  Test     ]  [[WindowsFeature]IIS]
VERBOSE: [A3CF5B7BB54E]:                            [[WindowsFeature]IIS] The operation 'Get-WindowsFeature' started: Web-Mgmt-Service
VERBOSE: [A3CF5B7BB54E]:                            [[WindowsFeature]IIS] The operation 'Get-WindowsFeature' succeeded: Web-Mgmt-Service
VERBOSE: [A3CF5B7BB54E]: LCM:  [ End    Test     ]  [[WindowsFeature]IIS]  in 2.1210 seconds.
VERBOSE: [A3CF5B7BB54E]: LCM:  [ Start  Set      ]  [[WindowsFeature]IIS]
VERBOSE: [A3CF5B7BB54E]:                            [[WindowsFeature]IIS] Installation started...
VERBOSE: [A3CF5B7BB54E]:                            [[WindowsFeature]IIS] Continue with installation?
VERBOSE: [A3CF5B7BB54E]:                            [[WindowsFeature]IIS] Prerequisite processing started...
VERBOSE: [A3CF5B7BB54E]:                            [[WindowsFeature]IIS] Prerequisite processing succeeded.
VERBOSE: [A3CF5B7BB54E]:                            [[WindowsFeature]IIS] Installation succeeded.
...
...
...
VERBOSE: [A3CF5B7BB54E]:                            [[WindowsFeature]WindowsDefenderFeatures] Prerequisite processing succeeded.
WARNING: [A3CF5B7BB54E]:                            [[WindowsFeature]WindowsDefenderFeatures] You must restart this server to finish the removal process.
VERBOSE: [A3CF5B7BB54E]:                            [[WindowsFeature]WindowsDefenderFeatures] Uninstallation succeeded.
VERBOSE: [A3CF5B7BB54E]:                            [[WindowsFeature]WindowsDefenderFeatures] Successfully uninstalled the feature Windows-Defender-Features.
VERBOSE: [A3CF5B7BB54E]:                            [[WindowsFeature]WindowsDefenderFeatures] The Target machine needs to be restarted.
VERBOSE: [A3CF5B7BB54E]: LCM:  [ End    Set      ]  [[WindowsFeature]WindowsDefenderFeatures]  in 9.5400 seconds.
VERBOSE: [A3CF5B7BB54E]: LCM:  [ End    Resource ]  [[WindowsFeature]WindowsDefenderFeatures]
VERBOSE: [A3CF5B7BB54E]:                            [] A reboot is required to progress further. Please reboot the system.
WARNING: [A3CF5B7BB54E]:                            [] A reboot is required to progress further. Please reboot the system.
VERBOSE: [A3CF5B7BB54E]: LCM:  [ End    Set      ]
VERBOSE: [A3CF5B7BB54E]: LCM:  [ End    Set      ]    in  135.5150 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 136.314 seconds
  • Exit out of your container and stop it to commit image
[a3cf5b7bb54e...]: PS C:\inetpub\wwwroot> exit

PS C:\WINDOWS\system32> Stop-Container iis

PS C:\WINDOWS\system32> Commit-Container -ContainerIdOrName iis -Repository artisticcheese/straightcommit

RepoTags                                 ID                   Created                        Size(MB)            
--------                                 --                   -------                        --------            
artisticcheese/straightcommit:latest     sha256:8f3ea8e9c6... 1/23/2017 6:27:35 PM           9,661.71            
  • Check the size of the layer you created.
PS C:\WINDOWS\system32> docker history artisticcheese/straightcommit
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
8f3ea8e9c66b        2 minutes ago                                                       177 kB              
7d4c79e586fd        11 days ago         cmd /S /C #(nop)  ENTRYPOINT ["C:\\Service...   280 MB              
<missing>           11 days ago         cmd /S /C #(nop) ADD file:d1c2ff374479851d...   1.88 GB             
<missing>           11 days ago         cmd /S /C powershell -Command Add-WindowsF...   7.68 GB      

As you can see it's pretty small addition (about 200 kB), roughly the same size as committing via dockerfile but what is important here is that as you can see "CREATED BY" column is empty which means you will never be able to upgrade to newer version of base image (like if patched version of microsoft/iis image is released) or for that matter will not be able to upgrade to newer OS/IIS either without redoing manual steps we just took.

⚠️ **GitHub.com Fallback** ⚠️