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

Running on .NET Alpine docker image #341

Closed
Lazer91 opened this issue May 23, 2023 · 3 comments
Closed

Running on .NET Alpine docker image #341

Lazer91 opened this issue May 23, 2023 · 3 comments

Comments

@Lazer91
Copy link

Lazer91 commented May 23, 2023

I'm struggling to make this work inside an Alpine-based .NET docker image, due to the dependency on glibc. Here's what I tried:

This works (it's Debian)

FROM mcr.microsoft.com/dotnet/aspnet:7.0
COPY bin/Release/net7.0/publish ./app
ENTRYPOINT ["dotnet", "/app/MyApp.dll"]

This doesn't work, glibc is missing in Alpine

FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine
COPY bin/Release/net7.0/publish ./app
ENTRYPOINT ["dotnet", "/app/MyApp.dll"]

I tried to add gcompact as per THIS but doesn't work (segmentation fault as soon as the lib is invoked in MyApp)

FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine
RUN apk add --no-cache gcompat libstdc++
COPY bin/Release/net7.0/publish ./app
ENTRYPOINT ["dotnet", "/app/MyApp.dll"]

I tried also sgerrand/alpine-pkg-glibc:

FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
   wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r1/glibc-2.35-r1.apk  && \
   apk add glibc-2.35-r1.apk
COPY bin/Release/net7.0/publish ./app
ENTRYPOINT ["dotnet", "/app/MyApp.dll"]

but it doesn't work, I get THIS issue.

Has anyone managed to make this work in an Alpine image? I read that it's not recommended to use glibc in Alpine due to the presence of musl.

@timyhac
Copy link
Collaborator

timyhac commented May 23, 2023

Do the libplctag core binaries work by themself for this setup?

@kyle-github
Copy link
Member

They might not. You'll probably need to build them using the musl libraries.

@Lazer91
Copy link
Author

Lazer91 commented May 25, 2023

Indeed we solved by building the native library in an Alpine VM. Here are the commands if anyone is interested:

apk update
apk add build-base gcc git cmake

git clone https://github.com/libplctag/libplctag.git

cd libplctag
mkdir -p build
cd build

cmake .. -DCMAKE_BUILD_TYPE=Release
make

Please note that:

  • The output libplctag.so that you will find in the output directory is just a 0 byte symbolic link. You will need to find the file it is pointing to (for example libplctag.so.2.5) and rename it to libplctag.so, then include it in your .NET solution with the "Copy always" action set.
  • To avoid the unwanted overwriting of the file at the program startup, the following line of code is required in your app (before any use of the libplctag library), as explained HERE
plctag.ForceExtractLibrary = false;

@Lazer91 Lazer91 closed this as completed May 25, 2023
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

3 participants