Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
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 if you already use Docker in your stack, then you may be interested in utilizing Aspose.Words in a Docker container.
Docker must be installed on your system. 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.
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.
To create the Hello World program, follow the steps below:
SkiaSharp.NativeAssets.Linux
.// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET.git. | |
using System; | |
using Aspose.Words; | |
namespace Docker | |
{ | |
internal class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
// Create document and save it in all available formats. | |
Document doc = new Document(); | |
DocumentBuilder builder = new DocumentBuilder(doc); | |
builder.Writeln("Hello from Aspose.Words!!!"); | |
foreach (SaveFormat sf in Enum.GetValues(typeof(SaveFormat))) | |
{ | |
if (sf != SaveFormat.Unknown) | |
{ | |
try | |
{ | |
doc.Save($"out{FileFormatUtil.SaveFormatToExtension(sf)}", sf); | |
Console.WriteLine("Saving {0}\t\t[OK]", sf); | |
} | |
catch | |
{ | |
Console.WriteLine("Saving {0}\t\t[FAILED]", sf); | |
} | |
} | |
} | |
} | |
} | |
} |
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.
The next step is to create and configure the Dockerfile.
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:
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:
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:
docker run --mount type=bind,source=C:\Temp,target=/TestOut --rm awtest from Docker
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:
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:
SkiaSharp does not work on Windows Nano Server due to a lack of some native dependencies, which is a known issue in SkiaSharp. 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:
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:
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"]
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"]
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"]
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"]
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.