How to create Docker file for HTML to RTF .Net

    The following is a project file for the .NET Core application with added Docker support.

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


<PackageReference Include="SautinSoft.HtmlToRtf" Version="*" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="*" />
<PackageReference Include="System.Drawing.Common" Version="*" />
<PackageReference Include="System.Security.Permissions" Version="*" />


To configure or customize a Docker image, you'll need to edit the Dockerfile.

When creating HTML to RTF files with images, System.Drawing.Common is used to process image data, which requires a libgdiplus package on a Linux container.

When creating RTF/DOCX files, the font files need to be present in the container. The official Linux images for .NET won't have any fonts installed. So, you'll need to copy the necessary font files to the Linux container, or install a font package like ttf-mscorefonts-installer, or add them as Private Fonts.

The following example shows how you can create HTML to RTF files from Docker containers and configure Docker images with Dockerfile.


FROM AS base

FROM AS build
COPY ["HtmlToRtfDocker.csproj", ""]
RUN dotnet restore "./HtmlToRtfDocker.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "HtmlToRtfDocker.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "HtmlToRtfDocker.csproj" -c Release -o /app/publish

FROM base AS final

# Update package sources to include supplemental packages (contrib archive area).
RUN sed -i 's/main/main contrib/g' /etc/apt/sources.list

# Downloads the package lists from the repositories.
RUN apt-get update

# Install System.Drawing.Common dependency.
RUN apt-get install -y libgdiplus

# Install Microsoft TrueType core fonts.
RUN apt-get install -y ttf-mscorefonts-installer

# Or install Liberation TrueType fonts.
# RUN apt-get install -y fonts-liberation

# Or some other font package...

COPY --from=publish /app/publish.


If you need a new code example or have a question: email us at or ask at Online Chat (right-bottom corner of this page) or use the Form below:

Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.