In this documentation topic you will learn how to run GroupDocs.Total for .NET in Docker container based on simple code examples.
Limitations
If the target framework is .NET 6 or over, due to limitations in the System.Drawing.Common version 6.0.0 (see Microsoft documentation), you need to add the following setting to the .csproj file.
In case packages are not available, you can add the contrib repository:
RUN sed -i'.bak''s/$/ contrib/' /etc/apt/sources.list
Basic Example
This is the most basic example that shows how to run GroupDocs.Total for .NET in Docker. The example demonstrates document conversion functionality using a simple console application.
Note
You can download this sample application from here.
Project Structure
The sample application has the following folder structure:
We’re using the official Microsoft .NET 6 SDK image to build and run the application. This approach provides a complete development environment with all necessary tools. Here are the most essential parts:
FROM mcr.microsoft.com/dotnet/sdk:6.0WORKDIR /app# Install dependenciesRUN sed -i'.bak''s/$/ contrib/' /etc/apt/sources.listRUN apt update && apt install -y \
libgdiplus \
libx11-dev \
fontconfig \
ttf-mscorefonts-installer# Copy the appCOPY . .# Run the appENTRYPOINT["dotnet","run","--framework","net6.0","--verbosity","normal"]
usingSystem.IO;usingGroupDocs.Conversion;usingGroupDocs.Conversion.Options.Convert;// Set the license (Optional)stringlicensePath=Path.GetFullPath("./GroupDocs.Total.lic");Licenselicense=newLicense();license.SetLicense(licensePath);// Initialize convert options and converterPdfConvertOptionsoptions=newPdfConvertOptions();Converterconverter=newConverter("./business-plan.docx");// Convert and save fileconverter.Convert("./output/business-plan.pdf",options);
To create the Docker image, run the following command in the directory containing the Dockerfile:
docker build -t groupdocs-total:basic-example .
To run the application and mount the output directory:
docker run -it --rm -v ${PWD}/output:/app/output groupdocs-total:basic-example
docker run -it --rm -v %cd%/output:/app/output groupdocs-total:basic-example
docker run -it --rm -v $(pwd)/output:/app/output groupdocs-total:basic-example
The application creates the output business-plan.pdf file and places it into the output folder on your host machine. You can download expected output file from here.
Command Explanation
-it: Runs the container in interactive mode
--rm: Automatically removes the container when it exits
-v: Mounts the host directory to the container directory for file output
Troubleshooting
The most common issues that can be resolved right away are font-related problems. Typically, you need to install the appropriate font that supports the character set used in your documents.
Chinese Characters
If your documents contain Chinese text and characters do not display correctly, you may need to install the SimSun font.
Option 1: Copy from a Windows machine
You can copy the SimSun font file (simsun.ttc) from a Windows system and include it in your Docker image:
# Copy SimSun font from local directory into the containerCOPY simsun.ttc /usr/share/fonts/truetype/simsun.ttc
# Update font cacheRUN fc-cache -f -v
π‘ Tip: You can find simsun.ttc in C:\Windows\Fonts on a Windows machine.
Option 2: Install compatible CJK font
Alternatively, you can download and install a compatible CJK font package directly in your Dockerfile:
Provides free replacements for Microsoftβs proprietary fonts. Many documents, especially DOCX, PPTX, and PDFs, use Microsoft fonts. On Linux systems, these arenβt available by default, so fonts-liberation ensures text renders correctly and preserves layout without needing the actual Microsoft fonts.
Includes:
Liberation Sans β substitute for Arial
Liberation Serif β substitute for Times New Roman
Liberation Mono β substitute for Courier New
fonts-dejavu-core
Provides high-quality, Unicode-complete fonts that extend the Bitstream Vera family. It offers very wide Unicode coverage, meaning it supports many symbols, mathematical characters, and international scripts. Itβs a default choice in many Linux distributions for general-purpose text rendering.
Includes:
DejaVu Sans
DejaVu Serif
DejaVu Sans Mono
Exceptions or Errors
If you experience any other exceptions when running the application, please contact us using the GroupDocs Free Support Forum and we’ll be happy to help.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.