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
In case you experience any other exeptions when running the application please contact us using 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.