How to run IIS on Windows Server Container on AWS

This article shows how to host IIS Web Site on a Container on Windows Server 2019 with Container Instance on AWS.

Launch an instance with Windows Server with Containers AMI

When Launching EC2, select Microsoft Windows Server 2019 Base with Containers. The rest of the steps are the same as creating an EC2 instance.

Start the instance and inspect

At Server Manager, you can see the “Containers” feature preinstalled with this Base AMI.

Docker Engine Service was running.

NAT Ethernet was also ready

Ran docker version cmdlet at Powershell, confirmed that docker is ready.

Pull Microsoft IIS docker Image

This Docker image published by Microsoft can be used to enable IIS Web Server Hosting Container.

docker pull mcr.microsoft.com/windows/servercore/iis

Run:

Create a Dockerfile with your website

Upon the docker page published by Microsoft, a Docker File is created.

Docker File lists command lines in a text file, which specifies automated build instructions.

# Run from the Microsoft IIS image

FROM mcr.microsoft.com/windows/servercore/iis

# Delete all previous files and folders under C:\inetpub\wwwroot from Container

RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*

# Set the directory as Working Directory

WORKDIR /inetpub/wwwroot

# Copy installer files from Content folder to Container

COPY Content/ .

DockerFile and Content folder having a Sample Web App are used for the build.

Build the IIS Container upon definition of DockerFile

Build a container at the working directory having DockerFile and Content folder.

docker build -t iis-site .

Run:

Run the built Container

Start the container

docker run -d -p 8000:80 --name myWebApp iis-site

-p is to publish a container port to host port, and the first number is host port and 2nd one is container port.

Web site is ready

docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" myWebApp

The returned IP address from the above cmdlet run is a private IP assigned by virtual Ethernet, which can be used between localhost and container.

For public access, the created website can be reachable with the EC2 Instance Public IP/DNS and with published port 8000.

More articles to read:

How to Install AWS CLI in Docker Container on Desktop Docker

How to Install Docker on Windows Server 2019

Leave a Comment