Read on:

Beginners’ Guide for Microsoft Hyper-V: Overview of Hyper-V – Part 1
Beginners’ Guide for Microsoft Hyper-V: How to Install Microsoft Hyper-V Using Server Manager – Part 2
Beginners’ Guide for Microsoft Hyper-V: How to Install Microsoft Hyper-V with PowerShell – Part 3
Read More

We have discussed many aspects of running Docker containers on a Windows Server, including installing Docker. Running an Internet Information Server as a Docker container is a very suitable containerized workload, as many businesses run full virtual machines to host single IIS websites. In this Windows IIS container for beginners’ walkthrough, we will consider pulling down an IIS container and running a simple IIS website using Docker in Windows.

Protect Your Data with BDRSuite

Cost-Effective Backup Solution for VMs, Servers, Endpoints, Cloud VMs & SaaS applications. Supports On-Premise, Remote, Hybrid and Cloud Backup, including Disaster Recovery, Ransomware Defense & more!

Why run IIS in a Docker container?

For years now, organizations have run IIS websites in full virtual machines. Virtual machines are now considered traditional infrastructure. Businesses are now looking to leverage the benefits of containerized workloads in their environment. The benefits of running applications inside containers are many. Containerized workloads allow applications to be quickly spun up and down as needed.

Containers are scalable, portable, and have all the dependencies included in the container image, making them excellent platforms for running applications like webservers in production.

Creating a docker file to build an IIS container

Let’s step through building a Windows IIS Docker container and see what is involved in this process. First, spinning up a new customized container of any variety is accomplished using a “docker file.” A docker file is a special file that contains instructions for Docker to build your container using the commands specified.
When we build an IIS container, the docker file specifies the base image of the container and any customizations we need to make to the IIS configuration for our Docker image.
To build our IIS container, we will use the following code for the docker file:

Download Banner

# escape=`
FROM mcr.microsoft.com/windows/servercore/iis

# Setup Remote IIS management
RUN powershell Install-WindowsFeature Web-Mgmt-Service; `
New-ItemProperty -Path HKLM:\software\microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 -Force; `
Set-Service -Name wmsvc -StartupType automatic;

#Add user for Remote IIS Manager Login

RUN net user iisadmin Password1 /ADD

RUN net localgroup administrators iisadmin /add

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

WORKDIR /inetpub/wwwroot

COPY . /inetpub/wwwroot

RUN dir

In the above docker file directives, we are configuring the container’s base image, mcr.microsoft.com/windows/servercore/iis. Then we configure the container with various configuration commands that do the following:

  • Enabling remote management
  • Setting the WMSVC service to start automatically
  • Adding a remote management user
  • Adding the remote management user to the administrators group
  • Removing any existing files in the inetpub\wwwroot directory
  • Setting the working directory
  • Copying files
  • Running a dir command to list out the files

Building a Windows IIS Docker container

We can build our IIS container image now that we have our docker file. To build the docker image for the IIS docker container, we can issue the following command:

docker build -t .

How to run IIS in Docker Container

Building a new docker IIS container using the customized docker file

The container should build successfully. You can see your new container image in your docker container images using the command:

docker image ls

How to run IIS in Docker Container

Listing docker images to verify the new IIS container is created successfully

Running the new Windows Docker IIS image

Now that we have the new Docker IIS image ready to go, we can run the container. To run a new Docker IIS container, we can use the command:

docker run -d -p 80:80 –name testwebsite testiis/testiis:latest

In the command above, we are telling Docker which port we want to expose externally and where the port translates to on the internal container side. The name parameter allows us to create a friendly name for the new container. Finally, we tell Docker which image we want to use for the container.

How to run IIS in Docker Container

Running the new Docker IIS container

Verifying connectivity to the new IIS website

At this point, we should be able to verify that we have connectivity to the new IIS website in Docker. We can browse to the localhost address, IP address, or hostname of the IIS container and it should pull up the website.

How to run IIS in Docker Container

Verifying the new Docker IIS website

Managing the IIS running in Docker

Now that we have a new IIS website running in Docker, can we manage it with the traditional IIS Manager console? Yes, as we recall, we enabled remote management and created a user for management. We can connect to the IIS site using the IIS Manager console with that information.

First, we need to get the internal Docker IP address for managing the container. To get your IP address for the running IIS container, we need to issue the command:

docker inspect

We should see the network information when we scroll down toward the bottom of the JSON output.

How to run IIS in Docker Container

The IP address of an IIS Docker container in Docker inspect output

With this internal IP address from the Docker host, we can manage the IIS website in Docker. Add a new connection in IIS Manager. Enter the IP address.

How to run IIS in Docker Container

Add a new connection using the Docker IP address in IIS Manager

Use the username and password configured in the Docker file to add the connection.

How to run IIS in Docker Container

Enter the username and password for the Docker IIS container

Name the connection to the Docker IIS container.

How to run IIS in Docker Container

Name the connection for the IIS Docker container

The connection is successfully added to the Docker IIS container.

How to run IIS in Docker Container

The Docker IIS connection is added successfully

Docker IIS container FAQs

What is a Docker file?

A Docker file is a special file that allows building a custom Docker container with the commands, components, and configurations you need in the environment.

Why run IIS websites in Docker?

Running simple IIS websites in full virtual machines is inefficient and not the best use of resources. Instead, you can more efficiently run IIS sites in Docker and have all the prerequisites required bundled in the container without worrying about the VM environment. Having IIS in Docker allows easily moving the website to a new Docker host and scaling the solution if needed.

What does Docker build do?

Docker build takes a Docker file and builds the Docker image specified by the file contents.

Wrapping Up

Running IIS websites in Docker containers is a great way to make the best use of resources and have all the underlying requirements for the website contained in the container. Furthermore, moving the container to another Docker host is easy if needed. In addition, each container is isolated from another. If you want further isolation, you can use Hyper-V isolation mode for your containers for even more robust security.

Beginners Guide for Microsoft Hyper-V: How to Install Microsoft Hyper-V in Windows Server Core – Part 4
Beginners Guide for Microsoft Hyper-V: Remote Management of Hyper-V – Part 5
Beginners Guide for Microsoft Hyper-V: How to Install Hyper-V Server – Part 6
Beginner’s Guide for Microsoft Hyper-V: What is Azure Stack HCI – Part 7
Beginner’s Guide for Microsoft Hyper-V: Windows Admin Center Hyper-V Management – Part 8
Beginner’s Guide for Microsoft Hyper-V: Configuration of Hyper-V Networking Best Practices – Part 9
Beginner’s Guide for Microsoft Hyper-V: Hyper-V Storage Best Practices and Configuration – Part 10
Beginner’s Guide for Microsoft Hyper-V: How to build a Virtual Lab with Hyper-V – Part 11
Beginner’s Guide for Microsoft Hyper-V: Top 10 PowerShell Commands for Hyper-V – Part 12
Beginner’s Guide for Microsoft Hyper-V: How to Create a Hyper-V Virtual Machine – Part 13
Beginner’s Guide for Microsoft Hyper-V: Hyper-V Shared Storage for Beginners – Part 14
Beginner’s Guide for Microsoft Hyper-V: How to Create Hyper-V Cluster – Part 15
Beginner’s Guide for Microsoft Hyper-V: What is Non-Uniform Memory Access (NUMA) – Part 16
Beginner’s Guide for Microsoft Hyper-V: Hyper-V Dynamic Memory – Part 17
Beginner’s Guide for Microsoft Hyper-V: Cluster Aware Updating (CAU) – Part 18
Beginner’s Guide for Microsoft Hyper-V: Hyper-V Containers – Part 19
Beginner’s Guide for Microsoft Hyper-V: Managing Windows Server Containers with Windows Admin Center – Part 20
Beginner’s Guide for Microsoft Hyper-V: What are Hyper-V Checkpoints – Part 21
Beginners Guide for Microsoft Hyper-V: How to Create Cluster Shared Volumes (CSVs) – Part 22
Beginners’ Guide for Microsoft Hyper-V: VHD vs VHDX Vs AVHD/AVHDX: Overview of Virtual Disk Formats – Part 23
Beginners’ Guide for Microsoft Hyper-V: Hyper-V Live Migration – Part 24
Beginners’ Guide for Microsoft Hyper-V: Hyper-V High Availability – Part 25
Beginners’ Guide for Microsoft Hyper-V: How to Export and Import Hyper-V VM’s – Part 26
Beginners’ Guide for Microsoft Hyper-V: How To Install Docker Container on Windows Server – Part 27
Beginners’ Guide for Microsoft Hyper-V: How to Run Linux Containers on Hyper-V – Part 28
Beginners’ Guide for Microsoft Hyper-V: Containers vs Virtual Machines – Part 29
Beginners’ Guide for Microsoft Hyper-V: What is Azure Arc VM Management – Part 30
Beginners’ Guide for Microsoft Hyper-V: Azure Features in Windows Admin Center – Part 31
Beginners’ Guide for Microsoft Hyper-V: What is Microsoft Azure Arc – Part 32
Beginners Guide for Microsoft Hyper-V: How to Create a Virtual Switch in Hyper-V using Windows Admin Center – Part 33
Beginners Guide for Microsoft Hyper-V: Managing Hyper-V Server with Azure Arc – Part 34
Beginners Guide for Microsoft Hyper-V: Learn How to Install MicroK8s on Windows Kubernetes – Part 35
Beginners Guide for Microsoft Hyper-V: Top 8 Basic Docker Commands You Should Know – Part 36
Beginners’ Guide for Microsoft Hyper-V: Windows Docker Container Networking in Hyper-V – Part 37

Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.

Rate this post