grpc/grpc

C#: Running in Alpine Linux docker container fails with System.IO.IOException: Error loading native library "/app/runtimes/linux/native/libgrpc_csharp_ext.x64.so"

Closed this issue · 6 comments

What version of gRPC and what language are you using?

C#, 1.12.0

What operating system (Linux, Windows, …) and version?

Docker, Alpine Linux

What runtime / compiler are you using (e.g. python version or version of gcc)

.NET Core 2.1

What did you do?

Created a ASP.NET Core 2.1 project and Dockerfile using an Alpine Linux base image.

FROM microsoft/dotnet:2.1.300-sdk-alpine AS builder
WORKDIR /

COPY . .
RUN dotnet publish WebApplication2/WebApplication2.csproj -o /dockerout/ -c Release

FROM microsoft/dotnet:2.1.0-aspnetcore-runtime-alpine
WORKDIR /app
EXPOSE 80

COPY --from=builder /dockerout .

ENTRYPOINT ["dotnet", "WebApplication2.dll"]

See https://github.com/cypressious/grpc-docker-issue for a reproducible sample.

What did you expect to see?

The application working

What did you see instead?

Unhaled Exception: System.IO.IOException: Error loading native library "/app/runtimes/linux/native/libgrpc_csharp_ext.x64.so"
   at Grpc.Core.Internal.UnmanagedLibrary..ctor(String[] libraryPathAlternatives)
   at Grpc.Core.Internal.NativeExtension.LoadUnmanagedLibrary()
   at Grpc.Core.Internal.NativeExtension.LoadNativeMethods()
   at Grpc.Core.Internal.NativeExtension..ctor()
   at Grpc.Core.Internal.NativeExtension.Get()
   at Grpc.Core.GrpcEnvironment.GrpcNativeInit()
   at Grpc.Core.GrpcEnvironment..ctor()
   at Grpc.Core.GrpcEnvironment.AddRef()
   at Grpc.Core.Channel..ctor(String target, ChannelCredentials credentials, IEnumerable`1 options)
   at WebApplication2.Startup.ConfigureServices(IServiceCollection services) in /WebApplication2/Startup.cs:line 16
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at WebApplication2.Program.Main(String[] args) in /WebApplication2/Program.cs:line 17

Anything else we should know about your project / environment?

Changing the Dockerfile to use a non-alpine image makes it work correctly

FROM microsoft/dotnet:2.1.300-sdk AS builder
WORKDIR /

COPY . .
RUN dotnet publish WebApplication2/WebApplication2.csproj -o /dockerout/ -c Release

FROM microsoft/dotnet:2.1.0-aspnetcore-runtime
WORKDIR /app
EXPOSE 80

COPY --from=builder /dockerout .

ENTRYPOINT ["dotnet", "WebApplication2.dll"]

Just hit the same issue, same error, same stack trace... :feelsgood:

It worked for me when I installed libc6-compat:

RUN apk update && apk add libc6-compat

Hmm. I thought I tried that. I will double check.

@vadimi this seems to have done the trick. thanks

We don't have a distrib test currently for testing our nugets on alpine linux, we should consider adding it in the future. Otherwise, there's not much we can do about this.

Closing this issue as things seem to be working fine if the right prerequisites are installed.