IIS in Windows Containers
A Windows container packages IIS and your site into one image that runs the same on any Windows host.
On this page · 5 min · Advanced
On this page
- Learning objectives
- Explanation
- Step-by-step screens
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Advanced
- Updated
- Nov 26, 2026
Related tutorials
Interview questions
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#
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
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#
- The base image already has IIS and ServiceMonitor.
- PowerShell is used for RUN steps.
- The default site content is replaced with your files.
- IIS settings are applied at build time, so every container is identical.
- 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#
Windows images won’t pull in Linux mode. Switch Docker Desktop to Windows containers.
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
docker run -d -p 8080:80 shop-iis
Mini quiz#
Which image would you use for an ASP.NET 4.8 app?
Want more? Practise all IIS MCQs · IIS interview questions
My notes#
Saved in this browser.