@svgvijay.chinna I have investigated the issue and determined that there is a missed dependency of libSkiaSharp.so
on Alpine Linux. Running the following command in the docker:
ldd libSkiaSharp.so
Returns the following:
/lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
libpthread.so.0 => /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
libdl.so.2 => /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
libm.so.6 => /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
libc.so.6 => /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by libSkiaSharp.so)
As you can see the dependency ld-linux-x86-64.so.2
is missed. I have installed gcompat
package to resolve this:
RUN apk add --no-cache gcompat
Here is my full Dockerfile:
FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine3.15 AS base
WORKDIR /app
# Required to make SkiaSharp 2.80.1 work. If use 2.80.3 SkiaSharp.NativeAssets.Linux.NoDependencies it is not required.
#RUN apk add --no-cache fontconfig
# Requred to make code works on 6.0-alpine3.15. See https://docs.microsoft.com/en-us/answers/questions/728280/running-net-6-project-in-docker-throws-globalizati.html
RUN apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib
# For debug purposes.
RUN apk add --no-cache bash
# Add the missed ld-linux-x86-64.so.2 dependency.
RUN apk add --no-cache gcompat
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["TestNet6.csproj", "."]
RUN dotnet restore "./TestNet6.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "TestNet6.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "TestNet6.csproj" -c Release -r linux-x64 --no-self-contained -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestNet6.dll"]
I have tested with a simple .NET6 console application. Here is my .csproj
file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<PropertyGroup>
<InvariantGlobalization>false</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspose.Words" Version="22.7.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.3" />
</ItemGroup>
</Project>
Note, I have used 2.80.3
version of SkiaSharp.NativeAssets
because there was a mistake in NoDependencies package in 2.80.1
and it still requires fontconfig
package (See comments in Dockerfile).
And here is my source code:
using Aspose.Words;
using System;
using System.Diagnostics;
namespace Aspose.NetCore.TestRunner
{
class Program
{
static void Main(string[] args)
{
License lic = new License();
lic.SetLicense("/temp/Aspose.Words.NET.lic");
Document doc = new Document("/temp/in.html");
doc.Save(@"/temp/out.pdf");
Console.WriteLine("Done");
}
}
}
Commands to build and run the docker image are the following:
docker build -t awtest .
docker run --mount type=bind,source=C:\Temp,target=/temp --rm awtest from Docker
In case if you need to check what is published to the container you can run the container as the following:
docker run --rm -it --entrypoint=/bin/bash awtest
but since Alpine docker image doesn’t have bash installed by default. You will need to add it (See Dokerfile).