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?
2
Answers
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:
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.
Try with
runtime-deps:7.0-alpine
instead, ie:or
The .NET Runtime Dependencies image
Alpine is a pretty slim distribution and doesn’t contain many of the dependencies found on other distributions, like
libgcc
.Publish Directly to a Container
.NET 7 added the ability to publish directly to a container. The linked docs show how this is done:
Microsoft.NET.Build.Containers
package to the projectContainerImageName
propertydotnet publish --os linux --arch x64 /t:PublishContainer -c Release
For self-published applications, the
runtime
image is used by default. It’s possible to change this using theContainerBaseImage
property incsproj
: