libplctag / libplctag.NET

A .NET wrapper for libplctag.
https://libplctag.github.io/
Mozilla Public License 2.0
194 stars 50 forks source link

Running on .NET Alpine docker image #341

Closed Lazer91 closed 1 year ago

Lazer91 commented 1 year ago

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 commented 1 year ago

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

kyle-github commented 1 year ago

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

Lazer91 commented 1 year ago

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:

plctag.ForceExtractLibrary = false;