Search code examples
asp.net.netdockerasp.net-coredotnet-publish

Dockerise ASP.NET Core app with Alpine image


I want my dockerised ASP.NET Core 7 app based on Alpine (not ASP.NET Core Runtime).

MyApp.csproj contains:

<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>linux-musl-x64</RuntimeIdentifier>

Dockerfile contains:

FROM alpine

But when I start a container, I get:

Error relocating /dist/MyApp: __cxa_pure_virtual: symbol not found
Error relocating /dist/MyApp: __cxa_pure_virtual: symbol not found
Error relocating /dist/MyApp: __cxa_pure_virtual: symbol not found
Error relocating /dist/MyApp: _ZTVN10__cxxabiv121__vmi_class_type_infoE: symbol not found
Error relocating /dist/MyApp: _ZTVN10__cxxabiv121__vmi_class_type_infoE: symbol not found
Error relocating /dist/MyApp: _ZTVN10__cxxabiv121__vmi_class_type_infoE: symbol not found

It works with the normal image (i.e. FROM mcr.microsoft.com/dotnet/aspnet).

The docs imply that with the correct RID (linux-musl-x64), this should work. But obviously it's missing dependencies.

How do I fix this?


Solution

  • You can find the list of Alpine packages that .NET requires at https://github.com/dotnet/dotnet-docker/blob/231835f7f8b1effdebbddea9521e34fa305e7459/src/runtime-deps/6.0/alpine3.18/amd64/Dockerfile#L11-L20. For .NET 6/7, those packages are the following:

    • ca-certificates
    • krb5-libs
    • libgcc
    • libintl
    • libssl3
    • libstdc++
    • zlib

    Make sure those packages are installed. These packages are necessary even when publishing as a self-contained app as the self-contained app only embeds the .NET runtime, not the native dependencies.