我使用 Visual Studio 2019(预览版)创建了第一个 Blazor 测试。回购协议是here https://github.com/mitkins/holly_test。当我在 VS 中点击 IISExpress 按钮时,一切都按预期工作。
但是,我想将我的应用程序部署到 Ubuntu/Dokku 服务器。因此,我一直在尝试弄清楚如何使用 Docker 设置我的服务器。到目前为止,我的 Dockerfile 中包含以下内容:
# Latest .NET Core from https://hub.docker.com/_/microsoft-dotnet-core-sdk/ (not the nightly one)
FROM mcr.microsoft.com/dotnet/core/sdk:3.0.100-preview6-disco AS build-env
WORKDIR /app
# Copy everything and build
COPY . ./
RUN dotnet restore "./HollyTest.Server/HollyTest.Server.csproj"
RUN dotnet publish "./HollyTest.Server/HollyTest.Server.csproj" -c Release -o out
# Latest ASP.NET Core from https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ (not the nightly one)
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0-preview6-disco
ENV ASPNETCORE_URLS=http://+:5000
EXPOSE 5000
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "HollyTest.Server.dll"]
应用程序编译并且服务器运行,但每次我访问服务器时都会收到 404。所以我在本地计算机上运行了上述命令:
cd app
dotnet restore .\HollyTest.Server\HollyTest.Server.csproj
dotnet publish "./HollyTest.Server/HollyTest.Server.csproj" -c Release -o out
cd out
dotnet .\HollyTest.Server.dll
然后当我跑步时curl localhost:5000
我看到以下内容:
Hosting environment: Production
Content root path: C:\Users\hmurphy\Documents\GitHub\app\out
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:5000/
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'Fallback {*path:nonfile}'
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'Fallback {*path:nonfile}'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 223.05540000000002ms 404
Application is shutting down...
在Visual Studio生成的日志中,看起来更健康:
Hosting environment: Development
Content root path: C:\Users\hmurphy\Documents\GitHub\HollyTest\HollyTest.Server
Now listening on: http://localhost:50873
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:50873/
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'Fallback {*path:nonfile}'
info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[6]
The file /index.html was not modified
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'Fallback {*path:nonfile}'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 326.5401ms 304 text/html
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
.
.
.
我假设我缺少某种配置/缺少一个步骤。与“内容根路径”有关吗?在里面./out
文件夹,没有HollyTest.Server
folder.
我对 ASP.NET Core(或 .NET 中的现代 Web 开发)没有太多经验。有人可以帮助我并指出我正确的方向吗?