IIS (Internet Information Services) · Advanced Operations

IIS in Windows Containers

A Windows container packages IIS and your site into one image that runs the same on any Windows host.

Advanced 5 min Lesson 43 of 45Covers IIS 10 on Windows Server 2019/2022/2025 and Windows 10/11.
0/45 in IIS
On this page · 5 min · Advanced

Learning objectives#

  • Choose the right base image
  • Write a Dockerfile for an IIS site
  • Configure IIS inside the image with PowerShell
  • Run and test the container

Explanation#

Windows containers need a Windows host (Windows Server, or Windows 10/11 with Docker Desktop switched to Windows containers). The container’s Windows version must be compatible with the host — use the ltsc2022 tags on Windows Server 2022.

mcr.microsoft.com/windows/servercore/iis gives IIS for static sites; mcr.microsoft.com/dotnet/framework/aspnet:4.8 adds ASP.NET for .NET Framework apps. ASP.NET Core apps normally use Linux containers with Kestrel instead of IIS.

Copy the site into C:\inetpub\wwwroot (or create a new site with PowerShell in a RUN step). The images start ServiceMonitor.exe w3svc, which keeps the container alive while IIS runs.

Map the port when running: docker run -p 8080:80. Logs are inside the container; LogMonitor can forward them to docker logs.

Step-by-step screens#

Drawings of IIS Manager in IIS 10 (Windows Server 2019/2022, Windows 10/11). The red numbers match the numbered actions under each picture; names on your computer will differ.

Loading pictures…

Code example: A static site on IIS in a container#

DockerfileDockerfile Illustrative
FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2022
SHELL ["powershell", "-Command"]


RUN Remove-Item -Recurse C:\inetpub\wwwroot\*
COPY site/ C:/inetpub/wwwroot/


# Example IIS setting inside the image: add a MIME type
RUN Import-Module WebAdministration; \
    Add-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site' -Filter system.webServer/staticContent \
      -Name '.' -Value @{ fileExtension = '.webmanifest'; mimeType = 'application/manifest+json' }


EXPOSE 80


# docker build -t shop-iis .
# docker run -d -p 8080:80 --name shop shop-iis
Expected output
http://localhost:8080 shows the site served by IIS inside the container. docker exec -it shop powershell opens a shell inside it.

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. The base image already has IIS and ServiceMonitor.
  2. PowerShell is used for RUN steps.
  3. The default site content is replaced with your files.
  4. IIS settings are applied at build time, so every container is identical.
  5. Port 80 inside maps to 8080 on the host.

Real-world use case#

A legacy ASP.NET 4.8 app is moved off an old server by packaging it in the aspnet:4.8 image, so it runs unchanged on a new Windows Server 2022 host.

Common mistakes#

Linux container mode

Windows images won’t pull in Linux mode. Switch Docker Desktop to Windows containers.

Host and image version mismatch

An ltsc2025 image won’t run on a 2022 host with process isolation. Match the tags.

Best practices#

  • Match image tag to host version
  • Configure IIS in the Dockerfile
  • Keep images small
  • Forward logs with LogMonitor

Remember this#

servercore/iis or framework/aspnet images.

ServiceMonitor keeps the container running.

docker run -p 8080:80.

Practice exercise#

Your task: Run the image shop-iis in the background with host port 8080 mapped to container port 80.

Show solution
Shell Illustrative
docker run -d -p 8080:80 shop-iis

Mini quiz#

IIS in Windows Containers quizMultiple choice Question 1 of 1

Which image would you use for an ASP.NET 4.8 app?

Score so far: 0/0

Want more? Practise all IIS MCQs · IIS interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.