在Docker中运行Blazor [英] Run Blazor in Docker

查看:371
本文介绍了在Docker中运行Blazor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Visual Studio 2019(Preview)创建了我的第一个Blazor测试.仓库位于此处.当我在VS中按下IISExpress按钮时,一切都会按预期进行.

I've created my first Blazor test using Visual Studio 2019 (Preview). The repo is here. Everything works as expected when I hit the IISExpress button in VS.

但是,我想将我的应用程序部署到Ubuntu/Dokku服务器.结果,我一直试图弄清楚如何使用Docker设置服务器.到目前为止,这是我在Dockerfile中拥有的内容:

However, I'd like to deploy my app to an Ubuntu/Dokku server. As a result, I've been trying to figure out how I might setup my server using Docker. Here's what I have so far in my 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.因此,我已经在本地计算机上运行了以上命令:

The app compiles and the server runs, but everytime I hit the server I get a 404. So I've run the above commands on my local machine:

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时,我看到以下内容:

Then when I run curl localhost:5000 I see the following:

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生成的日志中,它看起来更健康:

In the log generated by Visual Studio, it looks healthier:

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文件夹.

I'm assuming that I'm missing some sort of configuration/missing a step. Is it do with the "content root path"? In the ./out folder, there is no HollyTest.Server folder.

我对ASP.NET Core(或.NET中的现代Web开发)没有太多经验.有人可以帮助我,并指出正确的方向吗?

I don't have much experience with ASP.NET Core (or modern web development in .NET). Can anybody help me and point me in the right direction?

推荐答案

.NET Core Preview 6(

There well-known issue in Balzor on .NET Core Preview 6 (https://github.com/aspnet/AspNetCore/issues/11636) and (https://github.com/aspnet/AspNetCore/issues/11185)

要么等待Preview 7,要么添加到Dockerfile

Either you wait for Preview 7, or add to your Dockerfile

# After publish
COPY out/wwwroot/_content/hollytestclient out/wwwroot/

然后运行docker run -p 8081:5000 -it holly_test:latest

这篇关于在Docker中运行Blazor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆