0

Im trying to create a container that contains a IIS which hosts my blazor applications.

I got it all running with static HTML files but when I try to host a blazor app im getting the error in the browser:

You do not have permission to view this directory or page.

or

The page cannot be displayed because an internal server error has occurred.

When I restart the container and look up the logs i get the following:

Service 'w3svc' has been stopped

APPCMD failed with error code 4312

Failed to update IIS configuration


When I use a workaround with creating my own entrypoint and starting w3svc i'm stuck in a endless loop. My current dockerfile

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-20191210-windowsservercore-ltsc2019

COPY ./dotnet/dotnet-hosting-3.1.0-win.exe .
RUN powershell ./dotnet-hosting-3.1.0-win.exe /quiet /install

RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*
WORKDIR /inetpub/wwwroot
COPY ./output . # Contains compiled blazor hello world project

COPY ./config.ps1 .
RUN powershell ./config.ps1 # Creates new app and pool

COPY ./ContainerRunTime.ps1 .
ENTRYPOINT ./ContainerRunTime.ps1 # C:\\ServiceMonitor.exe w3svc

My OS is WinServer 2019

Norbert Bartko
  • 2,468
  • 1
  • 17
  • 36
  • 1
    make sure to create container command is correct [link1](https://github.com/microsoft/iis-docker/issues/157). you could refer some git hug issue regarding the issue [link2]( https://github.com/microsoft/iis-docker/issues/154) [link3](https://github.com/microsoft/IIS.ServiceMonitor/issues/16) [link4](https://stackoverflow.com/questions/39395145/can-i-run-a-dotnet-app-which-is-hosted-on-iis-in-a-docker-container) – Jalpa Panchal Dec 30 '19 at 02:58

1 Answers1

1

I finally made it work with the following Dockerfile.

Copy this Dockerfile in your project's root directory, it's important that the project got its own projectforlder.

# Use iis as base image and install dotnet 3.0.1 hosting pack
FROM microsoft/iis as base
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"]

ADD https://download.visualstudio.microsoft.com/download/pr/32b71802-0b4d-4064-a7e6-083b5155d3b1/080cf60a5c06be4ed27e2eac6c693f2f/dotnet-hosting-3.0.1-win.exe "C:/setup/dotnet-hosting-3.0.1-win.exe"
RUN start-process -Filepath "C:/setup/dotnet-hosting-3.0.1-win.exe" -ArgumentList @('/install', '/quiet', '/norestart') -Wait
RUN Remove-Item -Force "C:/setup/dotnet-hosting-3.0.1-win.exe"

##############################################################################################################

# Use dotnet core sdk as build image 
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.sln ./
COPY ./{PROJECT_NAME}/*.csproj ./{PROJECT_NAME}/
RUN dotnet restore

# Copy everything else and build app
COPY ./{PROJECT_NAME}/. ./{PROJECT_NAME}/
RUN dotnet publish -c Release -o out

##############################################################################################################

# Create final image
FROM base AS final
WORKDIR /inetpub/wwwroot/{PROJECT_NAME}

RUN Import-Module WebAdministration
RUN Remove-Website -Name 'Default Web Site'

# Create pool
RUN New-WebAppPool -Name '{PROJECT_NAME}-pool'; \
    Set-ItemProperty IIS:\AppPools\{PROJECT_NAME}-pool -Name managedRuntimeVersion -Value ''; \
    Set-ItemProperty IIS:\AppPools\{PROJECT_NAME}-pool -Name enable32BitAppOnWin64 -Value 0; \
    Set-ItemProperty IIS:\AppPools\{PROJECT_NAME}-pool -Name processModel.identityType -Value Service
# Create new Website
RUN New-Website -Name '{PROJECT_NAME}' \
    -Port 80 -PhysicalPath 'C:\inetpub\wwwroot\{PROJECT_NAME}' \
    -ApplicationPool '{PROJECT_NAME}-pool' -force

# Copy output from build img
COPY --from=build /app/out .

EXPOSE 80

Now replace all {PROJECT_NAME} with your project name and create and start the container:

docker build -t blazor-iis .
docker run -d -p 8080:80 --name blazor-iis-container blazor-iis

Now you can open your app in chrome

start chrome $(docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" "blazor-iis-container")
Norbert Bartko
  • 2,468
  • 1
  • 17
  • 36