How to Run Aspose.3D in Docker

Microservices, in conjunction with containerization make it possible to easily combine technologies. Docker allows you to easily integrate Aspose.3D 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.3D functionality, or if you already use Docker in your stack, then you may be interested in utilizing Aspose.3D in a Docker container.

Prerequisites

  • 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 2019, .NET Core 3.1 SDK is used in the example, provided below.

Application

In this example, you will create a simple console application that generates a 3D file and save it to all supported save formats. The application can then be built and run in Docker.

Creating the Console Application

To create the program, follow the steps below:

  1. Once Docker is installed, make sure that it uses Linux Containers (default). If necessary, select the Switch to Linux containers option from the Docker Desktops menu.
  2. In Visual Studio, create a .NET Core console application.
    todo:image_alt_text
  3. Install the latest Aspose.3D version from NuGet.
    todo:image_alt_text
  4. Since the application will be run on Linux, the appropriate native Linux assets must be installed. Start with the dotnet core sdk 3.1 base image and install libgdiplus libc6-dev.
  5. After adding all the required dependencies, write a simple program that creates a plane and changes its orientation and save it to all supported save formats:
    .NET
    using System;
    namespace Aspose.3D.Docker
    {
        class Program
        {
            static void Main(string[] args)
            {
                // Initialize scene object
                Scene scene = new Scene();
    
                // Set Vector
                scene.RootNode.CreateChildNode(new Plane() { Up = new Vector3(1, 1, 3) });
    
                //This will generate a plane that has customized orientation
                scene.Save("ChangePlaneOrientation.obj");
            }
        }
    }
    

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.3D 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).
  2. In the Dockerfile, specify:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster 
COPY fonts/* /usr/share/fonts/
WORKDIR /app
COPY . ./
RUN apt-get update && \
    apt-get install -y --allow-unauthenticated libgdiplus libc6-dev
RUN dotnet publish "Aspose.3D.Docker.csproj" -c Release -o /app/publish
ENTRYPOINT ["dotnet", "publish/Aspose.3D.Docker.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 3.1 image. Docker will download it when the build is run. The version of SDK is specified as a tag.
  • The command to copy everything to container, publish the application, and specify the entry point.
  • The command to install libgdiplus is run in the container. This is required by System.Drawing.Common.

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:

docker build -t actest .

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 actest from Docker

Images Supporting Aspose.3D

  • Aspose.3D for .NET Standard not support EMF and TIFF on Linux.

More Examples

1. To run the application in Windows Server 2019

  • Dockerfile
FROM microsoft/dotnet-framework:4.7.2-sdk-windowsservercore-ltsc2019
WORKDIR /app
COPY . ./
RUN dotnet publish "Aspose.3D.Docker.csproj" -c Release -o /app/publish
ENTRYPOINT ["dotnet", "publish/Aspose.3D.Docker.dll"]
  • Build Docker Image
docker build -t actest .
  • Run Docker Image
docker run --mount type=bind,source=C:\Temp,target=c:\TestOut --rm actest from Docker

See Also