IIS on Docker thanks to windows server 2016

INTRODUCTION :

Last year we published an article about the compatibility between Ikoula and Docker.

Aiming at going forward with new technologies, Ikoula dev teams have ran tests on Docker and Windows server 2016 Technical Preview 5.

We are going to describe in this article how to deploy a Windows Server 2016 TP5 virtual machine with Docker and its usage.



I. VM Setup

Our tests are made on a 2nd generation VM, 4Gb RAM, 4Vcpu with internet access.

VM setup is basic, we choose to install Windows Server 2016 standard TP5 (The VM will be a CORE system) :



Once installation is done, we apply a quick setup on the VM to get RDP access :

We type " start sconfig " to launch setup tool or CORE OS :



From there we enable what we need.

II. Docker installation and its requirements

We start to install " containers " feature with the command " install-windowsfeature containers " :



We reboot the VM.

We install the OS images we will need later : Nano Server and Windows Server Core

Install-PackageProviderContainerImage -Force

Install-ContainerImage-Name WindowsServerCore

Install-ContainerImage-Name NanoServer


Next, we download and run Docker service install script :

Invoke-WebRequest https://aka.ms/tp5/Update-Container-Host -OutFile update-containerhost.ps1

.\update-containerhost.ps1



Now Docker is installed and ready to use :



III. Docker usage

We can create a container based on one of the previous images :

docker run --name Test01 -it windowsservercore:10.0.14300.1000 cmd

With this command a new container named test01 based on the image windowsservercore will be deployed.
You will be automatically connected to a command line interface on that container.

From this CLI we can install for example web server IIS :



Now we make an image from this container :

docker commit Test01 windowsservercoreweb



We can now deploy from this image and to create a container with IIS preinstalled :



Now if we enter VM IP into a browser we get IIS default page of the container.

IV. Going forward (case study)

We are now going to imagine we want to create websites, we want to be able to manage and modify them without having to setup web server on our host. Containers will do that job.

These websites are stored into local folders, in our case :

C:\users\administrator\Documents\siteX (where X is a number)

We start by creating two folders (do not forget to set user rights) each folder contains a html test page to be able to check that configuration is working :



On the Docker side, we will create another image (based on webserver image) with IIS configured to point to a chosen empty folder.
Start the previously created container and execute following powershell commands :

Import-Module WebAdministration

Set-ItemProperty 'IIS:\Sites\Default Web Site' -name physicalpath -value c:\site01

Then we commit it in a new image named " windowssservercorewebmod "

After that we start two containers and we forward the 81 and 82 ports from the hosts to the 80 of both containers. We also mount the websites folders from the host to the folder we set in IIS before

docker run --name ikoula-web01 -p 81:80 -v C:\Users\Administrator\Documents\site1\:C:\site01 -dit windowsservercorewebmod


docker run --name ikoula-web02 -p 82:80 -v C:\Users\Administrator\Documents\site2\:C:\site01 -dit windowsservercorewebmod

We use arguments -dit at the end of the command to mount containers without attaching them.

  If we browse the websites we can see each container displaying its file :



Now we can modify our files on our host and run live tests thanks to web services running on the containers. The purpose of the containers is to run tests, they can be shut down when you don't need them.