Alpine Linux Docker error when running .NET Core 2.1 - Error relocating /app/app-name/libcoreclr.so: gCurrentThreadInfo: symbol not found
I created a Dockerfile to build and run a .NET Core 2.1 project using the new Alpine Linux images. When trying to run I get the following error:
Failed to load X?j?U, error: Error relocating /app/reactive-dotnet/libcoreclr.so: gCurrentThreadInfo: symbol not found
Failed to bind to CoreCLR at '/app/reactive-dotnet/libcoreclr.so'
Below is my csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="System.Reactive" Version="3.1.1" />
<PackageReference Include="Npgsql" Version="3.2.7" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
<ItemGroup>
<Folder Include="Model\" />
<Folder Include="Controllers\" />
<Folder Include="k8s\" />
<Folder Include="k8s\postgres\" />
<Folder Include="k8s\service\" />
<Folder Include="commands\" />
<Folder Include="database\" />
</ItemGroup>
</Project>
Below is the Dockerfile I'm using to build and run the app:
FROM microsoft/dotnet:2.1-sdk-alpine AS build
WORKDIR /app/app-name
COPY *.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -r linux-x64 -o out
# This builds the actual container that would run in k8s
FROM microsoft/dotnet:2.1-runtime-alpine AS runtime
RUN apk update && \
apk upgrade --available && \
apk add --update --no-cache libc6-compat
WORKDIR /app/app-name
COPY --from=build /app/app-name/out ./
# Add a user so that the container does not run as root
RUN adduser -G root appuser -D && \
chgrp -R 0 /app && \
chmod -R g+rwx /app
# Run this as the appuser
USER appuser
EXPOSE 8080
CMD [ "dotnet", "app-name.dll" ]
I dug around a little bit and have been trying do install various packages to overcome this. So far, I have tried to add:
Also, I tried removing the USER appuser line in the event that this was related to a permissions issue.
After some digging, I'm assuming this has to do with needing a threading library of some sort. A few of the packages above having threading libraries as dependencies, but did not fix the issue. If I'm missing a package, no problem to install, just curious on how to get this running. Thanks!
Here is my first guess. You are publishing the application as self-contained but trying to launch it on a shared framework. What happens if your final command is just to launch the executable itself and not try to launch it through the dotnet shared host?
I looked through the build settings in VS and have a compile target of "Executable" and checked the "Do not reference mscorlib.dll". When doing dotnet publish in my Dockerfile i'm purposely avoiding the --self-contained flag. The app is an ASP.NET application (microservice). However, this error seemed to be with the dotnet CLR rather than something having to do with ASP.NET which is why I posted the issue in this project.
For fun, I just tried building and running as a self contained app. I changed from 2.1-runtime-alpine to 2.1-runtime-deps-alpine. I got the same error.
-r on publish turns self-contained on by default. You can say --self-contained=false to turn it off. In your last scenario, how did you launch the application? Still trying to call dotnet app-name.dll?
I didn't realize that about -r. I've tried a couple different variants now.
Using the following two publish commands: dotnet publish -c Release -r linux-x64 --self-contained=false -o out or dotnet publish -c Release -o out I get the following error when running dotnet app-name.dll:
It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.App', version '2.1.0' was not found.
- Check application dependencies and target a framework version installed at:
/usr/share/dotnet/
- Installing .NET Core prerequisites might help resolve this problem:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from:
https://aka.ms/dotnet-download
I tried changing the publish command to dotnet publish -c Release -r linux-x64 -o out. I also changed the FROM line in my Dockerfile above to be FROM microsoft/dotnet:2.1-runtime-deps-alpine AS runtime. If I follow correctly, self-contained apps are meant for the deps image. I then ran ./app-name When I did that, I get same error as originally posted.
I'm almost wondering if there's something with one of the libraries that I'm importing that's causing this to go haywire. I started this out a few weeks ago on the .NET Core 2.0 framework running on an Ubuntu image. That ran without any issue. I was trying to move it to 2.1 because there were official Alpine images now. Just trying to think of different things that may be causing issues.
Yeah, it would be good to narrow down the variable that changed. I forgot that Alpine is a different flavor of Linux so when you publish you need linux-musl-x64 for the runtime identifier. I'm not sure if that's going to fix this though.
Just hit me when I posted the last comment I need to use the aspnetcore image. Closing as this was not a real thing. Thanks for talking through though. Appreciate the help!
Thanks @Petermarcu ! You're remark about linux-musl-x64 saved my skin! I kept getting this error: No such file or directory. As in:
$ docker run -it --entrypoint /bin/bash alpinetest
bash-4.4# ./AlpineTest
bash: ./AlpineTest: No such file or directory
For anyone else facing this issue: build for linux-musl-x64 instead of linux-x64
So close I can almost taste it.... now I keep getting the following error:
Failed to load `锟斤拷葠U, error: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /src/libhostpolicy.so)
An error occurred while loading required library libhostpolicy.so from [/src/]
@sjbeskur apk add libc6-compat && apk add libunwind-dev
@nicojs I'm getting "error : Project is targeting runtime 'linux-musl-x64' but did not resolve any runtime-specific packages. This runtime may not be supported by the target framework."
when I try to do that.
@ChristopherLClark
I think the linux-musl-x64 target is added since dotnet core 2.1. You might need to upgrade. Anyway, I'm not actively working on a dotnet core project right now, so cannot validate or test anything. Best of luck to you.
That's right, you need to be on at least 2.1
Most helpful comment
Yeah, it would be good to narrow down the variable that changed. I forgot that Alpine is a different flavor of Linux so when you publish you need
linux-musl-x64for the runtime identifier. I'm not sure if that's going to fix this though.