Closed chuchu closed 2 years ago
The errors that you are seeing are caused by trying to run musl compiler binary on non-musl Linux.
If you are targeting alpine, it is easiest to run the compilation on alpine (e.g. in Alpine docker container). Otherwise, you need to setup a cross-compilation environment.
You can start with standard dotnet alpine container: docker run -it mcr.microsoft.com/dotnet/sdk:6.0-alpine3.14
Once in the container, add package that are pre-requisite for NativeAOT: apk add clang gcc lld musl-dev build-base zlib-dev krb5-dev
And then you should be setup to compile your app.
Works. Thanks a lot! Just for reference here is the Dockerfile I have used:
FROM docker.io/library/alpine:latest AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine3.14 AS build
WORKDIR /src
COPY NativeAOTSample.csproj ./
RUN dotnet restore "./NativeAOTSample.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "NativeAOTSample.csproj" -c Release -o /app/build
FROM build AS publish
RUN apk add clang gcc lld musl-dev build-base zlib-dev krb5-dev
RUN dotnet publish "NativeAOTSample.csproj" -r linux-musl-x64 -c release -o /app/publish
FROM base AS final
RUN apk add libstdc++
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["./NativeAOTSample"]
The resulting image has only 25.1 MB :-)
I'm on Ubuntu 20.04.4 LTS and dot net 6.0.300 and trying to compile the Hello World sample application. It works like a charm for linux-x64 but I'm facing some challenges for linux-musl-x64.
My first problem was that libc.musl-x86_64.so.1 was missing. So I installed two more packages and created a new link.
This fixed the issue for me. But I'm stuck at this error now:
I guess the problem are the missing libraries libstdc++.so.6 and libgcc_s.so.1. But running ldd shows that they are available:
My goal is to build a binary which can be run in an alpine container. Does anyone has an idea what the problem might be?