首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在'/app/bin/Debug/netcoreapp3.1/‘中找不到执行应用程序所需的库“libhostpolicy.so”。

在'/app/bin/Debug/netcoreapp3.1/‘中找不到执行应用程序所需的库“libhostpolicy.so”。
EN

Stack Overflow用户
提问于 2021-03-06 16:37:22
回答 1查看 2.4K关注 0票数 1

我正在使用docker运行asp.net核心3.1MVC应用程序。我能够构建映像,但是当我运行映像时,它会引发以下错误:

代码语言:javascript
运行
复制
A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/bin/Debug/netcoreapp3.1/'.
Failed to run as a self-contained app. If this should be a framework-dependent app, add the /app/bin/Debug/netcoreapp3.1/Shopping2.runtimeconfig.json file specifying the appropriate framework.

Dockerfile

代码语言:javascript
运行
复制
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Shopping2.csproj", "Shopping2/"]
RUN dotnet restore "Shopping2/Shopping2.csproj"
COPY . .
WORKDIR "/src/Shopping2"
RUN dotnet build "Shopping2.csproj" -c Release -o /app/build

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

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

我不太清楚如何使用runtimeconfig.json。我在阅读之后添加了以下内容

Shopping2.runtimeconfig.json

代码语言:javascript
运行
复制
{
  "runtimeOptions": {
    "tfm": "netcoreapp3.1",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "3.1.0"
    },
    "configProperties": {
      "System.GC.Concurrent": false,
      "System.Threading.ThreadPool.MinThreads": 4,
      "System.Threading.ThreadPool.MaxThreads": 25
    }
  }
}

这一点也没有区别。

我试着根据<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>添加这就是答案,但是后来它给了我一个不同的错误:

代码语言:javascript
运行
复制
Unhandled exception. System.MissingMethodException: Entry point not found in assembly 'Shopping2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

下面是应用程序设置的屏幕截图

下面是我的.csproj

代码语言:javascript
运行
复制
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> // adding this changed the error
    <StartupObject></StartupObject>
    <OutputType>Library</OutputType>
    <LangVersion>latest</LangVersion>

  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
  </ItemGroup>

  <ItemGroup>
    <Content Update="appsettings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

</Project>
EN

Stack Overflow用户

发布于 2021-09-28 09:59:57

该错误是由COPY上的错误Dockerfile引起的。

为了调试这种错误,您应该构建从RUN dotnet build..开始的所有行(注释),然后将映像作为

docker run -it <imagename> /bin/sh

在提示运行ls时,您应该会看到一个与预期不同的文件夹树。

关于这个特殊的案子

代码语言:javascript
运行
复制
WORKDIR /src
# cd /src (create if not exist)

COPY ["Shopping2.csproj", "Shopping2/"] 
# Copy the csproj is in /src/Shopping2/Shopping.csproj

RUN dotnet restore "Shopping2/Shopping2.csproj"
# Restore in the /src/Shopping2/ folder

COPY . .
# THE ERROR!
# The content of the Docker run command folder is copied into /src
# probably on the docker image we have 
# /src/obj
# /src/bin
# /src/<all sources>
# /src/Shopping2/shopping2.csproj

WORKDIR "/src/Shopping2"
# cd to /src/Shopping2

RUN dotnet build "Shopping2.csproj" -c Release -o /app/build
# The error on build
# The compiler found ONLY the .csproj and the restored packages, it don't find the source code

作者通过将Dockerfile移出源文件夹,并在命令COPY . .停靠器上将Shopping2复制到/src,找到相同的文件夹并合并所有文件,从而解决了错误。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66508046

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档