---
title: "How to Run Aspose.Words in Docker"
---

```

## Purpose Summary

This page describes how to run Aspose.Words inside Docker containers.

```

Microservices, in conjunction with containerization make it possible to easily combine technologies. Docker allows you to easily integrate Aspose.Words functionality into your application, regardless of what technology is in your development stack.

In case you are targeting microservices, or if the main technology in your stack is not .NET, C++ or Java, but you need Aspose.Words functionality, or you already use Docker in your stack, then you may be interested in utilizing Aspose.Words in a Docker container.

## Prerequisites

- Docker must be installed onyoursystem. For information on how to install Docker on Windows or Mac, refer to the links in the "See Also" section.

- Also, note that Visual Studio 2017, .NET Core 2.2 SDK is used in the example, provided below.

## Hello World Application

In this example, you create a simple Hello World console application that makes a "Hello World!" document and saves it in all supported save formats. The application can then be built and run in Docker.

### Creating the Console Application

To create the Hello World program, followthe steps below:
1. Once Docker is installed, make sure that it uses Linux Containers (default).If necessary, select theSwitch to Linux containersoption from the Docker Desktops menu.
1. In Visual Studio, create a .NET Core console application.
![net-console-application](https://lh5.googleusercontent.com/PArWoC8_leOnhtaF-5BMb3b4jHwI3G03WoyMK3bXZpsQKN50YzvEQBwoRniyCWKIcdR0EZGuwn3S8Z0ZK6FQ4cjMSWgH3CwSqReW4bMt-3OjZjrdt9yuWbkMdhyNjwwaaYPC5Ylr)
1. Install the latest Aspose.Words version from NuGet. SkiaSharp will be installed as a dependency of Aspose.Words.
![skiasharp-dependency](https://lh3.googleusercontent.com/zWpvB5TLahC_OpJrHDML2131Vj_VK1vryTZBd_C3ZeOBdoUOc2vF_axEvwu9tytaL1maJv3qA2KoyP5fn7ae4_3cL23sXyoLoVysjgu8XEp6l0B2w5hgR9teh95_9mFd9X-4DGNN)
1. Since the application will be run on Linux, the appropriate native Linux assets must be installed. Start with the Debian base image and install `SkiaSharp.NativeAssets.Linux`.
1. When all required dependencies are added, write a simple program that creates a "Hello World!" document and saves it in all supported save formats:

{{< gist "aspose-words-gists" "47e15ad749897be465deebc2ff3e76dd" "aspose-words-docker.cs" >}}

Note that the "TestOut" folder is specified as an output folder for saving output documents. When running the application in Docker, a folder on the host machine will be mounted to this folder in the container. This will enable you to easily view the output generated by Aspose.Words in the Docker container.

### Configuring a Dockerfile

The next step is to create and configure the Dockerfile.

1. Create the Dockerfile and place it next to the solution file of your application. Keep this file name without extension (the default).
1. In the Dockerfile, specify:

```plain
FROM mcr.microsoft.com/dotnet/core/sdk:2.2
WORKDIR /app
RUN apt-get update && apt-get install -y libfontconfig1
COPY . ./
RUN dotnet publish -c Release -o out
ENTRYPOINT ["dotnet", "Aspose.Words.Docker.Sample/out/Aspose.Words.Docker.Sample.dll"]
```

The above is a simple Dockerfile, which contains the following instructions:

- The SDK image to be used. Here it is the .NET Core SDK 2.2 image. Docker will download it when the build is run. The version of SDK is specified as a tag.
- The working directory, which is specified in the next line.
- The command to install libfontconfig1 is run in the container.This isrequired by SkiaSharp.
- The command to copy everything to container, publish the application, and specify the entry point.

### Building and Running the Application in Docker

Now the application can be built and run in Docker. Open your favorite command prompt, change directory to the folder with the application (folder where the solution file and the Dockerfile are placed) and run the following command:

```plain
docker build -t awtest .
```

The first time this command is executed it may take longer, since Docker needs to download the required images. Once the previous command is completed, run the following command:

```plain
docker run --mount type=bind,source=C:\Temp,target=/TestOut --rm awtest from Docker
```

```

Pay attention to the mount argument, because, as mentioned earlier, a folder on the host machine is mounted into the container's folder, to easily see the results of the application execution. Paths in Linux are case sensitive.

```

## Images Supporting Aspose.Words

Aspose.Words is available for both .NET Framework and .NET Core. The .NET Core images are much smaller in size than .NET Framework images, which makes the .NET Core the better choice for creating microservices and for use in containers. It is possible to deploy apps to Linux Docker containers (for cross-platform deployment), which are lighter than Windows containers.

Official images for the .NET Core SDK are provided for:

- Debian 9 and 10
- Ubuntu 18.04 and 19.04
- Alpine 3.7 and 3.9
- Windows Nano Server

To work with graphics, Aspose.Words for .NET Standard depends on SkiaSharp. This limits the images Aspose.Words can be run on to the following:

- Debian 9 and 10
- Ubuntu 18.04 and 19.04
- Alpine 3.9

SkiaSharp does not work on Windows Nano Server due to a lack of some native dependencies,[which is a known issue in SkiaSharp](https://github.com/mono/SkiaSharp/issues/676). The issue will be resolved in 1.68.1.1 version of SkiaSharp. If you need to run Aspose.Words in a Windows container, use the .NET Framework base image with the .NET Framework version of Aspose.Words, which does not depend on SkiaSharp.

SkiaSharp is a wrapper around the native Skia library. The following runtimes are provided in the SkiaSharp NuGet package:

- osx
- tizen-armel
- tizen-x86
- win10-arm
- win10-x64
- win10-x86
- win-x64
- win-x86

To run it in Linux, you should use additional NuGet packages with the corresponding native assets, such as native builds of Skia library, listed below:

- *SkiaSharp.NativeAssets.Linux*- provides a native Skia build for x64 Debian based Linux distributions.
- *SkiaSharp.NativeAssets.Linux.NoDependencies*- the package is intended to be used in Linux distributions that do not have the libfontconfig dependency. Tested onRHEL 7 (x64).
- *Goelze.SkiaSharp.NativeAssets.AlpineLinux*- provides a native Skia build for x64 Alpine Linux 3.9.
- *Jellyfin.SkiaSharp.NativeAssets.LinuxArm*- provides a native Skia build for arm32 and arm64 Debian based Linux distributions.

## More Examples

1. In the above example, the application was run in an SDK image. SDK images are heavier than runtime images. The example below demonstrates how the Docker file should be modified in order to use the SDK image to build the application, and the runtime image to run it:
```plain
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /app
\# copy csproj and restore as distinct layers
COPY Aspose.Words.Docker.Sample/*.csproj ./Aspose.Words.Docker.Sample/
WORKDIR /app/Aspose.Words.Docker.Sample
RUN dotnet restore
\# copy and publish app and libraries
WORKDIR /app/
COPY Aspose.Words.Docker.Sample/. ./Aspose.Words.Docker.Sample/
WORKDIR /app/Aspose.Words.Docker.Sample
RUN dotnet publish -c Release -o out
\# copy to runtime environment
FROM mcr.microsoft.com/dotnet/core/runtime:2.2 AS runtime
WORKDIR /app
\# libfontconfig1 is required to properly work with fonts in Linux.
RUN apt-get update && apt-get install -y libfontconfig1
RUN apt install libharfbuzz-icu0
COPY --from=build /app/Aspose.Words.Docker.Sample/out ./
ENTRYPOINT ["dotnet", "Aspose.Words.Docker.Sample.dll"]
```
2. To run the application in Ubuntu 18.04, the Dockerfile remains practically the same (only the tag is changed):
```plain
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-bionic AS build
WORKDIR /app
\# copy csproj and restore as distinct layers
COPY Aspose.Words.Docker.Sample/*.csproj ./Aspose.Words.Docker.Sample/
WORKDIR /app/Aspose.Words.Docker.Sample
RUN dotnet restore
\# copy and publish app and libraries
WORKDIR /app/
COPY Aspose.Words.Docker.Sample/. ./Aspose.Words.Docker.Sample/
WORKDIR /app/Aspose.Words.Docker.Sample
RUN dotnet publish -c Release -o out
\# copy to runtime environment
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-bionic AS runtime
WORKDIR /app
\# libfontconfig1 is required to properly work with fonts in Linux.
RUN apt-get update && apt-get install -y libfontconfig1
RUN apt install libharfbuzz-icu0
COPY --from=build /app/Aspose.Words.Docker.Sample/out ./
ENTRYPOINT ["dotnet", "Aspose.Words.Docker.Sample.dll"]
```
3. To run the application in Alpine Linux, it is required to add the SkiaSharp native assetsand use the following Dockerfile:
```plain
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine3.9 AS build
WORKDIR /app
\# copy csproj and restore as distinct layers
COPY Aspose.Words.Docker.Sample/*.csproj ./Aspose.Words.Docker.Sample/
WORKDIR /app/Aspose.Words.Docker.Sample
RUN dotnet restore
\# copy and publish app and libraries
WORKDIR /app/
COPY Aspose.Words.Docker.Sample/. ./Aspose.Words.Docker.Sample/
WORKDIR /app/Aspose.Words.Docker.Sample
RUN dotnet publish -c Release -o out
\# copy to runtime environment
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-alpine3.9 AS runtime
WORKDIR /app
\# fontconfig is required to properly work with fonts in Linux.
RUN apk update && apk upgrade && apk add fontconfig && apk add harfbuzz
COPY --from=build /app/Aspose.Words.Docker.Sample/out ./
ENTRYPOINT ["dotnet", "Aspose.Words.Docker.Sample.dll"]
```
4. To run the application in RHEL 7, it is required to add the SkiaSharp native assetsand use the following Dockerfile:
```plain
FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build
WORKDIR /app
\# copy csproj and restore as distinct layers
COPY Aspose.Words.Docker.Sample/*.csproj ./Aspose.Words.Docker.Sample/
WORKDIR /app/Aspose.Words.Docker.Sample
RUN dotnet restore
\# copy and publish app and libraries
WORKDIR /app/
COPY Aspose.Words.Docker.Sample/. ./Aspose.Words.Docker.Sample/
WORKDIR /app/Aspose.Words.Docker.Sample
RUN dotnet publish -c Release -o out
\# copy to runtime environment
FROM kkamberta/dotnet-21-rhel7 AS runtime
WORKDIR /app
COPY --from=build /app/Aspose.Words.Docker.Sample/out ./
ENTRYPOINT ["/opt/rh/rh-dotnet21/root/usr/bin/dotnet", "Aspose.Words.Docker.Sample.dll"]
```

## See Also

- [Install Docker Desktop on Windows](https://docs.docker.com/docker-for-windows/install/)
- [Install Docker Desktop on Mac](https://docs.docker.com/docker-for-mac/install/)
- [Visual Studio 2017, .NET Core 2.2 SDK](https://docs.microsoft.com/en-us/dotnet/core/install/windows?tabs=netcore22#dependencies)
- [Switch to Linux containers](https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers)option
- Install[SkiaSharp.NativeAssets.Linux](https://www.nuget.org/packages/SkiaSharp.NativeAssets.Linux)
- Additional information on [.NET Core SDK](https://hub.docker.com/_/microsoft-dotnet-sdk)
- Use additional NuGet packages:[SkiaSharp.NativeAssets.Linux](https://www.nuget.org/packages/SkiaSharp.NativeAssets.Linux),[SkiaSharp.NativeAssets.Linux.NoDependencies](https://www.nuget.org/packages/SkiaSharp.NativeAssets.Linux.NoDependencies),[Goelze.SkiaSharp.NativeAssets.AlpineLinux](https://www.nuget.org/packages/Goelze.SkiaSharp.NativeAssets.AlpineLinux),[Jellyfin.SkiaSharp.NativeAssets.LinuxArm](https://www.nuget.org/packages/Jellyfin.SkiaSharp.NativeAssets.LinuxArm)
- [RHEL 7 (x64)](https://hub.docker.com/r/kkamberta/dotnet-21-rhel7)

------

## FAQ

1. **Q:** How do I apply an Aspose.Words license when running inside a Docker container?
   **A:** Copy the license file into the container (e.g., place it in the project folder) and load it at runtime with `License license = new License(); license.SetLicense("Aspose.Words.lic");`. Ensure the Dockerfile copies the `.lic` file (`COPY Aspose.Words.lic ./`) so it is available to the application.

2. **Q:** Can I use the `Document.Print()` method in a Linux‑based Docker container?
   **A:** No. Printing relies on Windows GDI+ APIs and is not supported on Linux containers. To print, run the application in a Windows container or on a Windows host outside Docker.

3. **Q:** Which output formats are supported when saving a document from Docker?
   **A:** Aspose.Words supports all standard formats, including PDF, DOCX, DOC, RTF, HTML, MHTML, EPUB, XPS, JPEG, PNG, BMP, TIFF, and SVG. Use `Document.Save("output.pdf", SaveFormat.Pdf);` or the appropriate `SaveFormat` enum value.

4. **Q:** Do I need to install additional native assets for fonts when using SkiaSharp in Docker?
   **A:** Yes. Linux containers require `libfontconfig1` (installed in the Dockerfile with `apt-get install -y libfontconfig1`). For Alpine, install `fontconfig` via `apk add fontconfig`. This provides the native dependencies needed by SkiaSharp for rendering.

5. **Q:** Is my existing Aspose.Words license retro‑compatible with older Aspose.Words versions running in Docker?
   **A:** Aspose.Words licenses are forward compatible; a license created for a newer version works with older versions, but not vice‑versa. Ensure the license file is placed in the container and loaded as described above.