Creating an IIS Base Image for Containers

Now we have a base image from the last post, we can use it to create other images and containers. Enter a PowerShell command and call Get-ContainerImage, we should see our WindowsServerCore image.
1
For the sake of this demonstration we will let our containers get an IP address from DHCP in the network, other situations will lead to different DHCP configurations with the containers and their IP address as completely throw away.
So again in the host machine create a new VM switch, I have it mapped to my External switch which will handle the DHCP.


New-VMSwitch –Name DHCP –NetAdapterName Ethernet


2
3
Now we create a new container which will become our base IIS image, so call

New-Container –Name ServerCoreIIS –ContainerImageName WindowsServerCore –SwitchName “DHCP”


4
Then start it up with Start-Container –Name ServerCoreIIS
5
We will need to enable the IIS feature, so enter a PowerShell session.
6
Then invoke the command to install the Web Server feature.


Invoke-Command –ScriptBlock {Install-WindowsFeature Web-Server}


7
It will run through and should show an Exit Code of Success
8
9
Get the IP address.
10
We should see the typical IIS welcome page when we browse to it.
11
Now call Stop-Container ServerCoreIIS
12
We now need to create an image from that container, so call the Get-Container command and pipe it to the New-ContainerImage like this.


Get-Container –Name ServerCoreIIS | New-ContainerImage –Publisher YourCompany –Name ServerCoreIIS –Version 1.0


13
I have named both the container and image the same so I can easily determine the relationship.
14
When calling Get-ContainerImage we should see our 2 base images.
15
Now we can create any number of containers based off the ServerCoreIIS image like this.
17
Start one up, enter a PowerShell session using Enter-PSSession –ContainerName “IISWeb01” –RunAsAdministrator and get the IP address
18
We should then see the IIS welcome page again when we browse to that address.
19
So now we have a static website running from c:\inetpub\wwwroot on the container. In the next post I will configure the base IIS image to run an MVC website and create a container from that.


Happy coding.