microsoft/Windows-Containers

How to deploy dotnet microservice in iis server inside Docker container

guruprasaddandagi037 opened this issue ยท 4 comments

Besically I created docker image and Container of ASP dotnet microservice. And then I installed iis server in the container So how to deploy microservice in the iis server which is inside container.

Hi. This is a great question and a key use case of ASP.NET and IIS containers. I've reached out to our people that create the Microsoft Learn tutorials to see if they'll help us create on for this use case.

I would recommend using the pre-configured ASP.NET image which includes:

  1. Windows Server Core as the base OS
  2. IIS 10 as Web Server
  3. NET Framework (multiple versions available)
  4. .NET Extensibility for IIS

Here's an example dockerfile.

# Use the ASP.NET image based on Windows Server Core 2022
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2022

# Copy the ASP.NET microservice to the container
# Replace 'path/to/your/aspnet/microservice' with the path to your ASP.NET microservice files
COPY path/to/your/aspnet/microservice C:\inetpub\wwwroot

# Expose port 80 for HTTP traffic
EXPOSE 80

# Optional: Expose port 443 if your application uses HTTPS
# EXPOSE 443

Once you have your dockerfile, you'll then want to build your docker image

docker build -t my-aspnet-app .

And then run the docker image (i.e. deploy the ASP.NET microservice)

docker run -d -p 80:80 my-aspnet-app

You can read this for more information on the ASP.NET images (https://mcr.microsoft.com/en-us/product/dotnet/framework/aspnet/about).

Hi, the answer to this is in the dockerfile. Dockerfile is the artifact used to build a container image. Your container image will have the base Operating System, with IIS installed (we have an image with this config already), and then your application deployed. A dockerfile is a set of instructions on how to deploy your application and package it as a container image so you can reuse it later, or in a different environment.

More specifically for IIS, what you need is the base container image we have already for IIS (https://hub.docker.com/_/microsoft-windows-servercore-iis) and then you need to build a dockerfile with the instructions on how to deploy your app. Once you have the dockerfile, you can build a container image and run a new container based off it.

You can find instructions on how to build a container image here: https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/manage-windows-dockerfile

You might also want to check this example: https://github.com/microsoft/iis-docker/blob/main/README.md. Please note on the FROM statement of your dockerfile, the name of the image needs to be: mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2022