May 15, 2016

Running IIS in Windows Docker Container in Amazon EC2

Windows Server 2016 Technical Preview 5 was released on 27th April 2016 & it’s well known by now that it supports docker with its windows server containers. Microsoft also started uploading windows server core with various application as docker images to docker hub.

I was wondering whether it’s possible to run Windows 2016 TP5 on an EC2 instance and launch a windows container inside the EC2 instance. EC2 officially supports only upto Windows 2012 R2 and I couldn’t find any 2016 AMI’s in Ireland region. Hence I decided to install Windows 2016 TP5 on local VirtualBox, upload it to S3 create AMI out of it and launch the EC2 instance.

Downloaded the ISO from the Technet Windows Server Evaluations, using the iso as boot image launch a VM and install Windows in it. Next step is to install the container feature, base container images, install docker and configure it. Quick Start guide in MSDN site clearly explains all the required step. I performed Scripted – Existing System setup without HyperV option since I don’t want to do each steps one by one.

Install and configure docker

Querying status of Windows feature: Containers...
Feature Containers is already enabled.
SUCCESS: The scheduled task "ContainerBootstrap" was successfully deleted.
Configuring ICMP firewall rules for containers...
Installing Docker...
Installing Docker daemon...
Creating Docker program data...
This script uses a third party tool: NSSM. For more information, see https://nssm.cc/usage
Downloading NSSM...
Extracting NSSM from archive...
Configuring NSSM for Docker service...
Starting Docker...
Waiting for Docker daemon...
Successfully connected to Docker Daemon.
The following images are present on this machine:
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

Installing ContainerImage provider...
Getting Container OS image (WindowsServerCore -MinimumVersion 10.0.14300.1000 -MaximumVersion 10.0.14300.1010) from OneGet (this may take a few minutes)...
WARNING: Based on customer feedback, we are updating the Containers PowerShell module to better
align with Docker. As part of that some cmdlet and parameter names may change in future releases.
 To learn more about these changes as well as to join in the design process or provide usage
feedback please refer to http://aka.ms/windowscontainers/powershell
Container base image install complete.
Creating a first boot layer...
Script complete!
PS C:\Users\Administrator> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
windowsservercore 10.0.14300.1000 dbfee88ee9fd 7 weeks ago 9.344 GB
PS C:\Users\Administrator>

Shutdown the VM and export it as OVA file as shown below.

VBoxManage.exe export Win2016TP5 -o D:\VirtualMachines\Win2016TP5.ova

Upload the OVA file to a S3 bucket.

$ aws s3 cp D:\VirtualMachines\Win2016TP5.ova s3://unique-prefix-prakash/
upload: D:\VirtualMachines\Win2016TP5.ova to s3://unique-prefix-prakash/Win2016TP5.ova
Completed 1021 of 1135 part(s) with 1 file(s) remaining

After the file got uploaded successfully import it as image to create the AMI.

$ aws ec2 import-image --description "Windows 2016" --disk-containers file://ImageConfig.json --region eu-west-1
{
    "Status": "active",
    "Description": "Windows 2016",
    "Progress": "2",
    "SnapshotDetails": [
        {
            "UserBucket": {
                "S3Bucket": "unique-prefix-prakash",
                "S3Key": "Win2016TP5.ova"
            },
            "DiskImageSize": 0.0,
            "Format": "OVA"
        }
    ],
    "StatusMessage": "pending",
    "ImportTaskId": "import-ami-ffmeshxq"
}

ImageConfig.json

[{
    "Description": "ImportWindowsOVA",
    "Format": "ova",
    "UserBucket": {
        "S3Bucket": "unique-prefix-prakash",
        "S3Key": "Win2016TP5.ova"
    }
}]

At this moment I was not sure whether the import image would be successful.

Checked the status of the task frequently to see how it goes.

$  aws ec2 describe-import-image-tasks
{
    "ImportImageTasks": [
        {
            "Status": "active",
            "Description": "Windows 2016",
            "Progress": "7",
            "SnapshotDetails": [
                {
                    "UserBucket": {
                        "S3Bucket": "unique-prefix-prakash",
                        "S3Key": "Win2016TP5.ova"
                    },
                    "DiskImageSize": 9516351488.0,
                    "Format": "VMDK"
                }
            ],
            "StatusMessage": "validated",
            "ImportTaskId": "import-ami-ffmeshxq"
        }
    ]
}
$  aws ec2 describe-import-image-tasks
{
    "ImportImageTasks": [
        {
            "Status": "active",
            "LicenseType": "AWS",
            "Description": "Windows 2016",
            "Platform": "Windows",
            "Architecture": "x86_64",
            "Progress": "59",
            "SnapshotDetails": [
                {
                    "UserBucket": {
                        "S3Bucket": "unique-prefix-prakash",
                        "S3Key": "Win2016TP5.ova"
                    },
                    "DiskImageSize": 9516351488.0,
                    "DeviceName": "/dev/sda1",
                    "Format": "VMDK"
                }
            ],
            "StatusMessage": "booting",
            "ImportTaskId": "import-ami-ffmeshxq"
        }
    ]
}
$  aws ec2 describe-import-image-tasks
{
    "ImportImageTasks": [
        {
            "Status": "completed",
            "LicenseType": "AWS",
            "Description": "Windows 2016",
            "ImageId": "ami-c9d0z4ba",
            "Platform": "Windows",
            "Architecture": "x86_64",
            "SnapshotDetails": [
                {
                    "UserBucket": {
                        "S3Bucket": "unique-prefix-prakash",
                        "S3Key": "Win2016TP5.ova"
                    },
                    "SnapshotId": "snap-a039504c",
                    "DiskImageSize": 9516351488.0,
                    "DeviceName": "/dev/sda1",
                    "Format": "VMDK"
                }
            ],
            "ImportTaskId": "import-ami-ffmeshxq"
        }
    ]
}

Once the AMI got created, launched an EC2 instance and was able to login successfully using the credentials that I configured in the VirtualBox image.

Pull IIS docker image from docker hub:

Launch the IIS windows container by invoking docker run

docker run --name iisdemo -it -p 80:80 microsoft/iis powershell

Hurray!! Welcome screen of IIS in windows container in Amazon EC2.

IIS Welcome Screen

Let’s create a new file to check how it goes.

PS C:\> echo "Hello World!! Windows Docker container on EC2" > C:\inetpub\wwwroot\index.html

Hello screen

This gives a hope that it will be available on EC2 not long after it goes GA.

© Prakash P 2015 - 2023

Powered by Hugo & Kiss.