.net - 在遇到问题的 Docker 上部署 Blazor Client(WebAssembly)

标签 .net docker .net-core blazor .net-6.0

当我在 Docker 上部署/运行项目时,我遇到了一个问题。 面临这样的问题,

Cannot use file stream for [/app/bin/Debug/net6.0/projectname.deps.json]: No such file or directory A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/bin/Debug/net6.0/'. Failed to run as a self-contained app.

  • The application was run as a self-contained app because '/app/bin/Debug/net6.0/projectname.runtimeconfig.json' was not found.
  • If this should be a framework-dependent app, add the '/app/bin/Debug/net6.0/projectname.runtimeconfig.json' file and specify the appropriate framework.

当我在 Visual Studio 2022 上使用 docker 运行项目时遇到问题。

face issue when I run project with docker on Visual Studio 2022.

如果有人对他有任何想法,请与我分享。

提前致谢。

最佳答案

使用 Nginx 反向代理服务器添加 Docker 文件

对于 Blazor Web Assembly,我们需要在项目根文件夹中添加“nginx.conf”

events { }
http {
   include mime.types;
   types {
      application/wasm wasm;
   }
   server {
      listen 80;
     # Here, we set the location for Nginx to serve the files looking for index.html
     location / {
        root .;
        try_files $uri $uri/ /index.html =404;
     }
  }
}

现在在 Dockerfile 中提到它就像👇👇

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["projectpath/projectname.csproj", "projectpath"]
RUN dotnet restore "projectpath/projectname.csproj"
COPY . .
WORKDIR "/projectpath"
RUN dotnet build "projectname.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "projectname.dll"]

FROM nginx:alpine AS final
WORKDIR /usr/share/nginx/html
#Copy from Environment(build/publish)
COPY --from=publish app/publish/wwwroot . 

现在在 docker 中构建并运行项目。

关于.net - 在遇到问题的 Docker 上部署 Blazor Client(WebAssembly),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70750490/

相关文章:

.net - Asp.Net Core RC2 与 Microsoft.Owin

mysql - 通过 ssh 使用 SQL 脚本失败,但直接在主机上启动时不会

.net-core - 从 EntityFrameworkCore 2.1 升级并破坏代码时添加的 SQL 'AS' 关键字

android - 华为 auth 服务与 .net core 3.1 集成,无法验证 JWT

c# - 在 BackGroundWorker 中使用定时器

jquery - UI 更改不会在 ASP.Net 应用程序中持续存在

c# - Windows 服务无法启动 'Error 1053: The service did not respond to the start or control request in timely fashion'

postgresql - Docker 如何向正在运行的容器添加卷?

python - Docker SDK for python中的auto_remove和remove有什么区别

.net-core - gitlab CI 上的 dotnet pack 或 nuget pack