How to run asp.net web api on IIS using docker

Viewed 1191

I am building a ASP.NET Web API application running on .NET framework 4.5. Here is my docker file:

FROM microsoft/dotnet-framework:4.7.2-sdk AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.sln .
COPY TestWebAPI/*.csproj ./TestWebAPI/
COPY TestWebAPI/*.config ./TestWebAPI/
RUN nuget restore

# copy everything else and build app
COPY TestWebAPI/. ./TestWebAPI/
WORKDIR /app/TestWebAPI
RUN msbuild /p:Configuration=Release


FROM microsoft/iis:10.0.14393.206

SHELL ["powershell"]

WORKDIR /inetpub/wwwroot
COPY --from=build /app/TestWebAPI/. ./

RUN Remove-Website -Name 'Default Web Site'
RUN New-Website -Name 'TestWebApi' -Port 80 \
    -PhysicalPath 'c:\inetpub\wwwroot' -ApplicationPool '.NET v4.5'
EXPOSE 80

CMD Write-Host IIS Started... ; \
    while ($true) { Start-Sleep -Seconds 3600 }

Then I ran following commands to build container :

 docker image build --tag v7 --file .\Dockerfile .
 docker container run --detach --publish 80 v7
docker ps to get the port number

When I go to specific port, the site does not load. There was no error while building containers. Is my docker file correct? What changes I need to make to ensure my site runs on IIS?

0 Answers
Related