在Docker容器中运行.NET API项目时无法本地访问index.html
.NET API Docker部署浏览器访问问题
我正尝试将.NET API部署到Docker容器中,使其可通过浏览器访问,但本地开发时遇到问题。代码仓库使用dev分支,此前API与UI项目一同运行,启动时默认运行UI项目,现在我正在移除UI项目(API的csproj文件中已注释相关代码)。我已在rardk.web.API项目中添加了wwwroot目录,并卸载了rardk.web.UI项目,但将API设为启动项目运行时,无法看到测试HTML页面。
Dockerfile
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base USER app WORKDIR /app EXPOSE 8080 EXPOSE 8081 FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src COPY ["rardk.web.UI/nuget.config", "rardk.web.UI/"] COPY ["rardk.web.API/rardk.web.API.csproj", "rardk.web.API/"] COPY ["rardk.web.BusinessLayer/rardk.web.BusinessLayer.csproj", "rardk.web.BusinessLayer/"] COPY ["rardk.web.ServiceLayer/rardk.web.ServiceLayer.csproj", "rardk.web.ServiceLayer/"] COPY ["rardk.web.Models/rardk.web.Models.csproj", "rardk.web.Models/"] # COPY ["rardk.web.UI/rardk.web.UI.esproj", "rardk.web.UI/"] RUN dotnet restore "./rardk.web.API/./rardk.web.API.csproj" COPY . . WORKDIR "/src/rardk.web.API" RUN dotnet build "./rardk.web.API.csproj" -c $BUILD_CONFIGURATION -o /app/build FROM build AS publish ARG BUILD_CONFIGURATION=Release RUN dotnet publish "./rardk.web.API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "rardk.web.API.dll"]
launchSettings.json
{ "profiles": { "http": { "commandName": "Project", "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": true, "applicationUrl": "http://localhost:5227" }, "https": { "commandName": "Project", "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": true, "applicationUrl": "https://localhost:7042;http://localhost:5227" }, "IIS Express": { "commandName": "IISExpress", "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "Docker": { "commandName": "Docker", "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", "environmentVariables": { "ASPNETCORE_HTTPS_PORTS": "8081", "ASPNETCORE_HTTP_PORTS": "8080" }, "publishAllPorts": true, "useSSL": true } }, "$schema": "https://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:36857", "sslPort": 44319 } } }
容器日志(含404错误)
2024-01-07 11:44:56 [16:44:56 INF] Now listening on: http://[::]:8080 2024-01-07 11:44:56 [16:44:56 INF] Now listening on: https://[::]:8081 2024-01-07 11:44:56 [16:44:56 INF] Application started. Press Ctrl+C to shut down. 2024-01-07 11:44:56 [16:44:56 INF] Hosting environment: Development 2024-01-07 11:44:56 [16:44:56 INF] Content root path: /app 2024-01-07 11:45:09 [16:45:09 INF] Request starting HTTP/1.1 GET http://localhost:32771/ - null null 2024-01-07 11:45:10 [16:45:10 INF] Request finished HTTP/1.1 GET http://localhost:32771/ - 307 0 null 130.1059ms 2024-01-07 11:45:10 [16:45:10 INF] Request starting HTTP/2 GET https://localhost:32770/ - null null 2024-01-07 11:45:10 [16:45:10 INF] Request finished HTTP/2 GET https://localhost:32770/index.html - 404 0 null 69.0943ms 2024-01-07 11:45:10 [16:45:10 INF] Request reached the end of the middleware pipeline without being handled by application code. Request path: GET https://localhost:32770/index.html, Response status code: 404 2024-01-07 11:45:50 [16:45:50 INF] Request starting HTTP/1.1 GET http://localhost:32771/ - null null 2024-01-07 11:45:50 [16:45:50 INF] Request finished HTTP/1.1 GET http://localhost:32771/ - 307 0 null 1.7569ms 2024-01-07 11:45:50 [16:45:50 INF] Request starting HTTP/2 GET https://localhost:32770/ - null null 2024-01-07 11:45:50 [16:45:50 INF] Request finished HTTP/2 GET https://localhost:32770/index.html - 404 0 null 84.2565ms 2024-01-07 11:45:50 [16:45:50 INF] Request reached the end of the middleware pipeline without being handled by application code. Request path: GET https://localhost:32770/index.html, Response status code: 404
内容的提问来源于stack exchange,提问作者muttley91
相关产品推荐
相关产品推荐

