Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error loading shared library libwasmtime in alpine docker image #82

Open
willhausman opened this issue Dec 23, 2021 · 7 comments
Open

Comments

@willhausman
Copy link

I am experiencing this error when trying to build my docker image that uses wasmtime.

Unhandled exception. System.DllNotFoundException: Unable to load shared library 'wasmtime' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: Error loading shared library libwasmtime: No such file or directory
   at Wasmtime.Engine.Native.wasm_engine_new()
   at Wasmtime.Engine..ctor()

I stopped trying to build my own docker image and instead used the https://github.com/bytecodealliance/wasmtime-dotnet/tree/main/examples/hello sample project. The only thing I changed was to use <PackageReference Include="Wasmtime" Version="0.32.0-preview1" /> instead of the ProjectReference.

I tried 3 different Dockerfiles:

# FROM mcr.microsoft.com/dotnet/sdk:5.0-bullseye-slim
# FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine
# FROM mcr.microsoft.com/dotnet/sdk:5.0-focal
COPY . /build
WORKDIR /build
RUN dotnet build -c Release
ENTRYPOINT ["dotnet", "run"]

All 3 build successfully with docker build -t test .. When run with docker run test, Debian and Ubuntu both print Hello from C#, WebAssembly! as expected, but alpine throws the above exception.

@peterhuene
Copy link
Member

peterhuene commented Jan 5, 2022

Currently the wasmtime-dotnet package bundles a wasmtime executable that is not targeted for musl libc.

Try installing the libc6-compat package into your alpine-based image. That might be enough to get wasmtime loaded.

If not, you may either need to install a full glibc into your image or rebuild both the wasmtime library targeted against musl libc and the wasmtime-dotnet package to bundle the musl-libc-targeted wasmtime. That's obviously easier said than done, though.

If the upstream Wasmtime repo starts producing musl libc artifacts, I can easily update the wasmtime-dotnet package to bundle it for the musl RIDs.

@willhausman
Copy link
Author

@peterhuene what would it take to make use of the aarch64 artifacts from upstream? I recently started working with an M1 MacBook Pro, and am now getting this same behavior locally. Unable to load shared library wasmtime.

@peterhuene
Copy link
Member

@willhausman is that without using alpine, right? It should be easy enough to bundle aarch64 RID artifacts in the package, we're just not doing so yet.

Right now it only includes the x86_64 artifacts.

@willhausman
Copy link
Author

Correct, without alpine. I can open a separate issue if you prefer.

@peterhuene
Copy link
Member

That'd be great, thanks!

@KIT-IT
Copy link

KIT-IT commented Feb 1, 2024

Working for me!

[ALPINE ] alpine:3.18

RUN apk add libwasmtime --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing

@thangchung
Copy link

Just got the same problem on alpine:3.18 on .NET 8 (I used dotnet-opa-wasm for authorization with OPA policies)

For those people who couldn't make it work. The full solution is as below.

FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine3.18 AS base
RUN addgroup -g 1000 -S <username> && \
    adduser -u 1000 -S <username> -G <username>
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories
RUN apk update --no-cache && apk upgrade --no-cache
RUN apk add libwasmtime --repository=dl-cdn.alpinelinux.org/alpine/edge/testing
# cut of for brevity
# ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants