How to Run Aspose.Slides in Docker
Supported OS
Aspose.Slides can run inside docker containers using .NET Core platform. In general, Aspose.Slides supports all container types (OS) types that the .NET Core platform supports. However, the GDI or libgdiplus has to be available and correctly set up on the containers involved.
To use Docker, you have to first install it on your system. To learn how to install Docker on Windows or Mac, use these links:
You can also run Docker on Linux and Windows Server by following instructions on these pages:
-
Install and configure Docker on Linux (make install libgdiplus)
-
Install and configure Docker on Windows Server Core
Installation and configuration for Docker on Windows Server Nano is not supported. Unfortunately, Windows Server Nano doesn’t contain the graphic sub-system on board. It does not contain gdiplus.dll, which the System.Drawing.Common library requires, and it cannot be used with the Aspose.Slides library.
While it is possible to run Linux containers in Windows, we recommend you run them natively on Linux (even on a Linux installed manually on a VM using VirtualBox).
Installing and Configuring Docker on Linux (apt-get libgdiplus)
- OS: Ubuntu 18.04.
- Dockerfile: Dockerfile-Ubuntu18_04_apt_get_libgdiplus
This docker file contains instructions for building a container image with libgdiplus package installed from Ubuntu’s official package repositories.
Here’s the docker file contents:
FROM microsoft/dotnet:2.1-sdk-bionic AS build
\# install libgdiplus
RUN apt-get update -y && apt-get install -y apt-utils
RUN apt-get install -y libgdiplus && apt-get install -y libc6-dev
\# create mount points
VOLUME /slides-src
\# build and test Aspose.Slides on start
WORKDIR /slides-src
CMD ./build/netcore.linux.tests.sh
Let’s review what each line of code in the docker file means:
- The container’s image is based on the microsoft/dotnet:2.1-sdk-bionic image (the image already built by Microsoft and published on docker’s public hub). This image contains the already installed dotnet 2.1 SDK. Bionic suffix means that Ubuntu 18.04 (codename bionic) will be taken as a container’s OS. By changing the suffix, it is possible to change the underlying OS (for example: stretch – Debian 9, alpine – Alpine Linux). In that case, the docker file content modification will be required (for example, changing ‘apt-get’ to ‘yum’).
FROM microsoft/dotnet:2.1-sdk-bionic AS build:
- Updates database of available packages and install apt-utils package.
RUN apt-get update -y && apt-get install -y apt-utils
- Installs ‘libgdiplus’ and ‘libc6-dev’ packages required by System.Drawing.Common library.
RUN apt-get install -y libgdiplus && apt-get install -y libc6-dev
- Declares /slides-src folder as a mounting point which we will be uses to provide access to slide-net sources folder on the host machine.
VOLUME /slides-src
- Sets slides-src as a working directory inside the container.
WORKDIR /slides-src
- Declares a default command which will be run on the container start in case if the explicit command is not specified.
CMD ./build/netcore.linux.tests.sh
According to instructions in the docker file, the resulting container’s image will have Ubuntu 18.04 OS, dotnet-sdk, libgdiplus and libc6-dev packages already installed. Also, this image will have a predefined mount point and predefined command on run.
To build an image using this docker file, you have to go to slides-netuil docker folder and execute:
$ docker build -f Dockerfile-Ubuntu18_04_apt_get_libgdiplus -t ubuntu18_04_apt_get_libgdiplus .
-f Dockerfile-Ubuntu18_04_apt_get_libgdiplus – option specifies which docker file to use.
-t ubuntu18_04_apt_get_libgdiplus – specifies tag (name) for the resulting image.
'.' – specifies the context for docker. In our case, the context is a current folder and it is empty—since we choose to provide slides-net sources as mounting point (this allows us not to rebuild docker image on each change in sources)
The result of the execution should look like this:
Successfully built 62dd34ddc142
Successfully tagged ubuntu18_04_apt_get_libgdiplus:latest
To ensure that the new image was added to the local images repository:
$ docker images
\----
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu18_04_apt_get_libgdiplus latest 62dd34ddc142 2 minutes ago 1.78GB
Once the image is ready, we can run it using this command:
$ docker run -it -v pwd/../../:/slides-src --add-host dev.slides.external.tool.server:192.168.1.48 ubuntu18_04_apt_get_libgdiplus:latest
-it – specifies that the command should be run interactively, allowing us to see the output and capture the input.
-v pwd
/../../:/slides-src – specified the folder for the predefined mounting point—since the current working dir is slides-netuildockerthen slides-src folder in container will point to slides-net folder on the host. pwd
is used to specify relative path.
–add-host dev.slides.external.tool.server:192.168.1.48 – modifies container’s hosts file to resolve dev.slides.external.tool.server url.
ubuntu1804aptgetlibgdiplus:latest – specifies the image to run container.
The result of the command above will be an output of netcore.linux.tests.sh (since it was defined as a default command for the container):
Restoring packages for /slides-src/targets/.NETCore/tests/Aspose.Slides.FuncTests.NetCore/Aspose.Slides.FuncTests.NetCore.csproj...
Restoring packages for /slides-src/targets/.NETStandard/main/Aspose.Slides.DOM.NetStandard/Aspose.Slides.DOM.NetStandard.csproj...
Restoring packages for /slides-src/targets/.NETStandard/main/Aspose.Slides.CompoundFile.NetStandard/Aspose.Slides.CompoundFile.NetStandard.csproj...
Installing System.Text.Encoding.CodePages 4.4.0.
Installing System.Drawing.Common 4.5.0.
...
Results File: /slides-src/build-out/netstandard20/test-results/main/Aspose.Slides.FuncTests.NetCore.trx
Total tests: Unknown. Passed: 2110. Failed: 108. Skipped: 210.
...
Results File: /slides-src/build-out/netstandard20/test-results/main/Aspose.Slides.RegrTests.NetCore.trx
Total tests: 2124. Passed: 1550. Failed: 103. Skipped: 471.
From the result, it is clear that log files from Func and Regr tests were placed to /build-out/netstandard20/test-results/main/ directory. Also, about 200 tests failed in total—and all these are rendering issues related to required fonts absence on the container.
To override the default command of the container on a run, we could use this command:
$ docker run -it -v pwd/../../:/slides-src --add-host dev.slides.external.tool.server:192.168.1.48 ubuntu18_04_apt_get_libgdiplus:latest /bin/bash
So, instead of netcore.linux.tests.sh, the /bin/bash will be executed and it will provide an active terminal session of a container from which it can be run (./build/netcore.linux.tests.sh). This approach can be useful in troubleshooting scenarios.
Installing and Configuring Docker on Linux (make install libgdiplus)
- OS: Ubuntu 18.04.
- Dockerfile: Dockerfile-Ubuntu18_04_make_libgdiplus
At the moment, Ubuntu contains only version 4.2 of libgdiplus while version 5.6 is already available on the product’s official site. To test the latest version of libgdiplus, we need to prepare an image with libgdiplus built from the sources.
Let’s review the docker file content:
FROM microsoft/dotnet:2.1-sdk-bionic AS build
\# build latest stable libgdiplus
RUN apt-get update -y
RUN apt-get install -y libgif-dev autoconf libtool automake build-essential gettext libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev
RUN git clone -b 5.6 https://github.com/mono/libgdiplus
WORKDIR /libgdiplus
RUN ./autogen.sh
RUN make
RUN make install
RUN ln -s /usr/local/lib/libgdiplus.so /usr/lib/libgdiplus.so
\# create mount points
VOLUME /slides-src
\# build and test Aspose.Slides on start
WORKDIR /slides-src
CMD ./build/netcore.linux.tests.sh
The only difference is the build latest stable libgdiplus section. This section installs all necessary tools to build libgdiplus, clones sources, and then builds them and installs them to the right location. Everything else is the same as Install and configure Docker on Linux (apt-get libgdiplus).
Note: Do not forget to use different image tags (name) for the resulting image on docker build and docker run commands:
$ docker build \-f Dockerfile-Ubuntu18_04_apt_get_libgdiplus \-t ubuntu18_04_make_libgdiplus .
$ docker run \-it \-v pwd/../../:/slides-src \--add-host dev.slides.external.tool.server:192.168.1.48 ubuntu18_04_make_libgdiplus:latest
Install and configure Docker on Windows Server Core
- OS: Ubuntu 18.04.
- Dockerfile: DockerfileWinServerCore
Note: Windows 10 Pro or Windows Server 2016 is required to run Windows containers.
Unfortunately, Microsoft does not provide Windows Server Core image with the dotnet SDK installed, so we have to install it manually:
# escape=
FROM microsoft/windowsservercore:1803 AS installer-env
#set powershell default executor
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
\# escape=
FROM microsoft/windowsservercore:1803 AS installer-env
#set powershell default executor
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
\# Retrieve .NET Core SDK
ENV DOTNET_SDK_VERSION 2.1.301
ENV DOTNET_PATH "c:/Program Files/dotnet"
RUN Invoke-WebRequest -OutFile dotnet.zip https://dotnetcli.blob.core.windows.net/dotnet/Sdk/$Env:DOTNET_SDK_VERSION/dotnet-sdk-$Env:DOTNET_SDK_VERSION-win-x64.zip;
$dotnet_sha512 = 'f2f6cc020f89dc4d4f8064cc914cffabde0ce422715138778a6bcbbb6803ca66d6fd967097a0209c47c89b85dd9e93db48486ac86999bd3a533e45b789fcea89';
if ((Get-FileHash dotnet.zip -Algorithm sha512).Hash -ne $dotnet_sha512) {
Write-Host 'CHECKSUM VERIFICATION FAILED!';
exit 1;
};
Expand-Archive dotnet.zip -DestinationPath $Env:DOTNET_PATH;
#return cmd as default executor
SHELL ["cmd", "/S", "/C"]
\# In order to set system PATH, ContainerAdministrator must be used
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;c:/Program Files/dotnet"
USER ContainerUser
\# create mount points
VOLUME c:/slides-src
#build and test Aspose.Slides on start
WORKDIR c:/slides-src
CMD .\external\buildtools\nant\nant.exe -buildfile:.\build\netcore.tests.build -D:obfuscate_eaz_use_mock=true -D:slidesnet.run.func.tests=true -D:slidesnet.run.regr.tests=true
The resulting image will be built over microsoft/windowsservercore:1803 image provided by the Microsoft on docker hub. The dotnet-sdk of the specified version will be downloaded and unpacked; the system’s PATH variable will be updated to contain the path to dotnet executable. The last line defines the command that executes func & regr tests on the container using nant.exe as a default action on the container run.
Command to build the image:
docker build -f Dockerfile_WinServerCore -t winservercore_slides .
Command to run the image:
docker run -it --cpu-count 3 --memory 8589934592 -v e:\Project\Aspose\slides-net:c:\slides-src winservercore_slides:latest
Note: The command for Windows container uses 2 extra arguments:
-cpu-count 3
-memory 8589934592
They set the number of cores and the amount of memory available for the container. By default, only 1 core and 1GB of RAM are available for the Windows container (Linux container’s don’t have any limitations by default).
Also, 1 argument is missed comparing to the same command we used to run the Linux container:
-add-host dev.slides.external.tool.server:192.168.1.48
Because container running on Windows just doesn’t require external.tool.server.
The result of the command above should look like this:
NAnt 0.92 (Build 0.92.4543.0; release; 6/9/2012)
Copyright (C) 2001-2012 Gerry Shaw
http://nant.sourceforge.net
netcore20_runtests:
[delete] Deleting directory 'c:\slides-src\build-out\netcore20\test-results\'.
[mkdir] Creating directory 'c:\slides-src\build-out\netcore20\test-results\'.
...
[exec] Results File: C:\slides-src\/build-out/netcore20/test-results//main\Aspose.Slides.FuncTests.NetCore.trx
[exec] Total tests: 2338. Passed: 2115. Failed: 19. Skipped: 204.
...
[exec] Results File: C:\slides-src\/build-out/netcore20/test-results//main\Aspose.Slides.RegrTests.NetCore.trx
[exec] Total tests: 2728. Passed: 2147. Failed: 110. Skipped: 471.