Question

A fatal error was encountered. The library 'libhostpolicy.so' required

I am running dotnet core 2.0 console project. Ran into the following error when trying to run it from Docker.

A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app'.

 46  62064  46
1 Jan 1970

Solution

 39

For me it was the following line that I had to add to the project file's PropertyGroup section that did the trick:

<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

Project file excerpt

2019-12-04

Solution

 9

So none of the above answers worked for me, but I finally found the problem, it was something in the .csproj file of the API, and it was causing the docker container hosting the API not to start with the message in the thread title.

This was the line that had been added in PropertyGroup node, presumably when someone had published the file for windows, and then checked in the updated .csproj

<RuntimeIdentifier>win-x64</RuntimeIdentifier>

As it turns out this is a publish option. Removing this sets the project to a default value of portable (in the UI) which is "any" in the file if it were explicitly specified. Removing the line above fixed the problem for me.

Edit

As a side note, I was able to leave the RuntimeIdentifier in the API .csproj file alone (kept win-x64 value) by changing my Dockerfile dotnet publish args to:

RUN dotnet publish ./src/API.csproj --self-contained --runtime linux-musl-x64 --configuration Release --output /app/publish

The important parts being the addition of --self-contained and --runtime linux-musl-x64 for alpine-linux ... this image: mcr.microsoft.com/dotnet/aspnet:3.1-alpine

The build image for this is mcr.microsoft.com/dotnet/sdk:3.1

2021-05-28