Docker provides an isolated environment for services and applications. In this topic we containerize sample application that is using GroupDocs.Viewer. You can learn more about conteinerization at Introduction to .NET and Docker.
Running GroupDocs.Viewer in Docker is straightforward. First we prepare a sample application that uses the GroupDocs.Viewer NuGet metapackage (which restores GroupDocs.Viewer.Net60 for net8.0) and then we build a Docker image and run the application in a Docker container.
In this documentation article, we’re going to use an Official .NET Docker image based on the Debian Linux distribution.
Prerequisites
Docker: Docker must be installed on your system. Refer to the official Docker documentation for detailed installation instructions check Get Docker.
.NET Application: In this topic we’ll run a sample .NET 8 application. You can download it from here. Alternatively, you can use your own application based on the code snippets provided below.
To create Docker image add a Dockerfile and a .dockerignore file to your project.
FROM mcr.microsoft.com/dotnet/sdk:8.0WORKDIR /app# Add `contrib` archive area to package sources listRUN sed -i 's/^Components: main$/& contrib/' /etc/apt/sources.list.d/debian.sources# Download the package lists from the repositories# and install two packages `fontconfig` and `ttf-mscorefonts-installer`RUN apt update && apt install -y \
fontconfig \
ttf-mscorefonts-installer # Copy the application and restore packagesCOPY . .RUN dotnet restore # Run the applicationENTRYPOINT["dotnet","run"]
The Dockerfile installs the following packages to provide font support for GroupDocs.Viewer on Linux:
fontconfig: This library provides font configuration, discovery, and customization.
ttf-mscorefonts-installer: This package provides Microsoft TrueType core fonts. It’s available in the contrib archive area. (Note: Using non-free fonts may have licensing implications, so be sure to check the license terms.)
Build Docker image
At this point we’re ready to build Docker image. Make sure that Docker is up and running, navigate to DemoApp directory and type the following in command line to build the image.
docker build -t viewer-demo-app .
-t - is used to name and tag the image. We name the image viewer-demo-app with no tag.
. - build context path. In this example it is current directory.
Run Docker container
To run our containerized application use the following command in the DemoApp directory.
docker run --rm -v ${pwd}/output:/app/output viewer-demo-app
--rm - Removes the container and cleanups file system on completion.
-v ${pwd}/output:/app/output - Maps ./output directory on our host OS to /app/output directory in Docker container.
After you run the application, the ./output directory will contain two files: page-1.html and page-2.html due to trial limitations. To render all the files you have to set a valid license. Learn more about evaluation and free trial limitations at How to Evaluate GroupDocs.Viewer.
Conclusion
This topic demonstrated containerizing a sample .NET 8 application with Docker for running GroupDocs.Viewer.
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.