Hi,
I have .NET core 8.0 web api application on my Windows 64 bit OS. I want to generate image so that it will be deploy on IIS inside the docker. I am going to use Windows container for this. Please provide me Dockerfile which will create the image of .net core web api, publish it in inetpub location and create site and map to that location to run through IIS.
Thanks,
Mahendra
I am able to create the IIS site inside the Docker and also placing published code at docker inetpub location through Dockerfile. Site is showing as started. but when access through browser it shows 500 Internal error. May be some IIS permissions required. Please check my Dockerfile below and suggest any changes.
(I am using Windows container)
Stage 1: Build the application
FROM mcr.microsoft.com/dotnet/sdk:8.0-nanoserver-1809 AS build
WORKDIR /source
Copy the project file(s) and restore any dependencies
COPY *.csproj ./
RUN dotnet restore
Copy the rest of the application code
COPY . .
Publish the application
RUN dotnet publish -c Release -o /app/publish
Stage 2: Create the IIS runtime image
FROM Microsoft Artifact Registry AS runtime
SHELL [“powershell”, “-Command”, “$ErrorActionPreference = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’;”]
Install necessary features for ASP.NET
RUN Install-WindowsFeature NET-Framework-45-ASPNET;
Install-WindowsFeature Web-Asp-Net45
Create a directory for your application
RUN New-Item -Path ‘C:\inetpub\wwwroot\reportapi’ -ItemType Directory
Copy the published application files from the build stage to the IIS directory
COPY --from=build /app/publish/ C:/inetpub/wwwroot/reportapi/
Grant IIS_IUSRS read access to the app directory
RUN icacls “C:\inetpub\wwwroot\reportapi” /grant IIS_IUSRS:R /T
Remove the default website
RUN Remove-WebSite -Name ‘Default Web Site’
Create a new website in IIS pointing to your application
RUN New-Website -Name ‘reportapi’ -Port 80 -PhysicalPath ‘C:\inetpub\wwwroot\reportapi’ -ApplicationPool ‘.NET v4.5’
Expose the port your application will run on
EXPOSE 80
Copy ServiceMonitor.exe from the microsoft/iis image
COPY --from=Microsoft Artifact Registry C:\ServiceMonitor.exe C:\ServiceMonitor.exe
Start IIS when the container starts
CMD [“C:\ServiceMonitor.exe”, “w3svc”]
Now I could able to Host my .NET core API on IIS inside the Docker.
It was about to add ASP.NET Core Hosting Bundle. After adding it I can see the result in browser.
Thanks,
Mahendra