Set up LEADTOOLS Document Service in a Docker Container

This tutorial shows how to set up the LEADTOOLS Document Service in a Docker container.

Overview  
Summary This tutorial covers how to set up the LEADTOOLS Document Service using Docker.
Completion Time 30 minutes
Visual Studio Project Download tutorial project (33 MB)
Platform JavaScript Application using Docker
IDE Visual Studio 2017, 2019
Development License Download LEADTOOLS

Required Knowledge

You will need:

Setting the License File

The first step is to set up the license file. Open the ServiceHelper.cs file located in ...\DocumentServiceDotNet\src\Tools\Helpers\. Go to line 368 and find the _SetLicense_ function. Replace the _SetLicense_ function with the following code.

C#
public static void SetLicense() 
{ 
    string licString = "[License]\n" + "COPY AND PASTE YOUR LEADTOOLS.lic LINE 51 HERE"; 
    string developerKey = "COPY AND PASTE YOUR DEVELOPER KEY HERE"; 
    byte[] licBytes = System.Text.Encoding.UTF8.GetBytes(licString); 
    RasterSupport.SetLicense(licBytes, developerKey); 
    IsLicenseChecked = !RasterSupport.KernelExpired; 
} 

The only portion of the LEADTOOLS.lic file that is required for this tutorial is line 51. Copy the entire line and paste it where indicated in the above code.

The LEADTOOLS developer key is in the LEADTOOLS.lic.key file. Copy and paste the entire contents of this file into the developerKey variable as indicated in the above code.

Creating the Docker File

Open the DocumentServicesDotNet folder. Add a new file called Dockerfile. This file will contain all the instructions for Docker to build the Document Service. Copy and paste the following code to the Dockerfile.

### Building the build environment image 
FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build-env 
WORKDIR /app 
 
# Copy everything and build 
COPY . ./ 
RUN dotnet restore core/DocumentService.csproj 
RUN dotnet publish -c Release -o out core/DocumentService.csproj 
 
### Building the runtime image 
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1 
WORKDIR /temp 
 
# Add package source 
RUN echo "deb http://ftp.us.debian.org/debian stretch main contrib" >> /etc/apt/sources.list 
 
# Generate the APT cache 
ENV DEBIAN_FRONTEND noninteractive 
RUN apt-get update \ 
    && apt-get install -y apt-utils wget 
 
# Install the LEAD dependencies 
RUN apt-get install -y \ 
    uuid-dev uuid-runtime gcc g++ libc-dev-bin \ 
    linux-libc-dev libx11-6 libx11-dev libxt6 \ 
    libxt-dev sqlite3 libsqlite3-dev libfreetype6 
 
# Install Microsoft fonts (http://askubuntu.com/a/25614) 
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections 
RUN apt-get install -y \ 
    fontconfig ttf-mscorefonts-installer 
 
# Install wkhtmltopdf 
RUN wget -q https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb 
RUN apt install -y --allow-unauthenticated \ 
    ./wkhtmltox_0.12.5-1.stretch_amd64.deb 
RUN ldconfig 
 
# Clean up APT cache 
RUN rm -rf /var/lib/apt/lists/* 
 
# Delete the temp files 
WORKDIR /app 
RUN rm -rf /temp 
 
EXPOSE 80 
 
# Copy and deploy application 
COPY --from=build-env /app/core/out . 
 
ENTRYPOINT ["dotnet", "DocumentService.dll"] 

Create a Docker Ignore File

Next create a file called .dockerignore. This file is used by Docker to ignore specified documents. This will reduce the amount of time Docker takes to build the project since it will not have to migrate the entire project into the container when it is being built. Copy and paste the following into the .dockerignore file.

core\bin\ 
core\obj\ 

Building the Docker Container

Next open the Terminal and migrate to the DocumentServiceDotNet folder. Use the command below:

docker build -t documentservice .

It may take a few minutes for Docker to complete. Once completed the image can be run.

Running the Docker Container

Once the Docker image can be run, use the following command:

docker run -p 30000:80 documentservice

The -p flag binds the container port 30000:80 to localhost:30000. Port 30000 is used because the Document Viewer assumes that this port will be available to service its requests.

Go to the browser and navigate to http://localhost:30000. The following page should be displayed.

Document Service Landing Page

Wrap-up

This tutorial showed how to set up the LEADTOOLS Document Service in a Docker Container and run on local host.

See Also

Help Version 21.0.2023.3.1
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.