How to Install Desktop Docker on Windows 10 and Run IIS

This article shows how to install docker windows 10 and host an IIS Container using a Docker Desktop on Windows 10 OS.

There are 2 selectable Linux and Windows Container modes in Docker Desktop, and Windows Container Mode was selected to use Microsoft ServerCore IIS image.

WebApp will be coped to C:\inetpub\wwwroot of Container with DockerFile, and the App runs from the published port.

Turn Windows Features ON

In order to run Windows Containers, “Hyper-V” and “Containers” Windows Features are to be enabled.

If you could not enable them, it is possible that the BIOS setting for Virtualization is disabled.

The features can be enabled by settings as above, or the following cmdlet can be executed with PowerShell. Restart PC after.
Enable-WindowsOptionalFeature -Online -FeatureName $("Microsoft-Hyper-V", "Containers") -All

Download Docker Desktop and install Docker for Windows 10

From Docker Hub, download Docker Desktop for Windows. Run the downloaded installer.

Installation was completed with defaults.

Install WSL2 Kernel Update

When the .NET exception occurred, a Dialog asked to install the WSL2 kernel update.

From the Microsoft link, the WSL2 Kernel Update installer was downloaded and installed. Rebooted the PC.

Now, the docker engine started without any issues, and I could see Docker Engine and Docker Desktop Services were running.

Switch to Windows Containers

There are 2 selectable Container modes on Docker Desktop: Linux and Windows.

I wanted to use Microsoft Windows ServerCore OS-based IIS image, and Windows Container mode is to be selected from the Docker Desktop system tray, docker whale icon.

Pull Microsoft IIS docker Image

As another example, Windows Server 2019 Container on AWS, the Docker image published by Microsoft was 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.

Now Web site is ready

Typing web address using published port 8000 to localhost ( http://localhost:8000/myWebApp/) on PC, I could validate the web App was running.

More articles to read:

How to Install AWS CLI in Docker Container on Desktop Docker

How to install MSI on Windows Container

Leave a Comment