Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

.NET Core 3.0 application runs on IIS Express but not docker

I am new to docker and microservices. As part of my job, I need to containerise a .NET Core application.

It runs fine on IIS express, and loads the following url on startup (which is the correct one):

localhost:9999/swagger/

But when I try running it in a Docker container, it starts up with the following url:

localhost:9999

even if I manually add '/swagger', the application does not run.

What am I doing wrong here?

Here are the contents of my launchSettings.json file:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:9999/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger/",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "web": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "http://localhost:5000/swagger/",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Docker": {
        "commandName": "Docker",
        "launchBrowser": true,
        "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger/",
        "publishAllPorts": true,
        "httpPort": 9999
    }
  }
}

And here is how my configuration looks like:

Image link

Following are the contents of my Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-nanoserver-1809 AS build
WORKDIR /src
COPY ["HostServer.csproj", ""]
RUN dotnet restore "./HostServer.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "HostServer.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "HostServer.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HostServer.dll"]
question from:https://stackoverflow.com/questions/66056491/net-core-3-0-application-runs-on-iis-express-but-not-docker

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can view the log information using the docker logs -f Container and provide your docker run command.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...