We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

.NET 6 in Docker

The project I’m working on is a .NET 6.0 and using the Aspose.Words to convert Docx files to PDF. It is working fine if I run it on Windows 10 directly but having issues with embedded images when run under Docker, both on Linux and Windows.

Based on the documentation, it requires quite older version of operating systems which are 2-3 versions late for the currently available versions of .NET 6.0? What are my options for this if I want to run it using .NET 6.0 while in the Docker environment? Are there ways to make it work with the default images for .NET 6.0? Thanks!

@vdolosa Most likely, you have missed to add reference to SkiaSharp.NativeAssets.Linux. In this case images will not be rendered under Linux. Aspose.Words for .NET Standard uses SkiaSharp to deal with graphics, to make it work on Linux you have to add reference either to SkiaSharp.NativeAssets.Linux or to SkiaSharp.NativeAssets.Linux.NoDependencies

If you add reference to SkiaSharp.NativeAssets.Linux, you should also install libfontconfig1 in your system. SkiaSharp.NativeAssets.Linux depends on this library. You can use the following command to install it:

apt-get update && apt-get install -y libfontconfig1

If you do not have rights to install packages, or other reasons not to install libfontconfig1, you can simply use SkiaSharp.NativeAssets.Linux.NoDependencies, which does not require installation of libfontconfig1.

I have tested with a simple console project with .NET 6.0 official image. Here is my docker file:

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
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

COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestNet6.dll"]

In my .csproj file I have the following:

<Project Sdk="Microsoft.NET.Sdk">


    <PackageReference Include="Aspose.Words" Version="22.5.0" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.3" />


and the following simple code:

License lic = new License();

Document document = new Document("/temp/in.docx");

The example is run using the following two commands:

docker build -t awtest .
docker run --mount type=bind,source=C:\Temp,target=/temp --rm awtest from Docker

Regarding Windows images. SkiaSharp does not work properly on Windows Nano Server because of know limitation. https://github.com/mono/SkiaSharp/issues/1105
However, you can use Windows Server Core images without any limitations.

1 Like