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 |
You will need:
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.
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.
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 imageFROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build-envWORKDIR /app# Copy everything and buildCOPY . ./RUN dotnet restore core/DocumentService.csprojRUN dotnet publish -c Release -o out core/DocumentService.csproj### Building the runtime imageFROM mcr.microsoft.com/dotnet/core/aspnet:2.1WORKDIR /temp# Add package sourceRUN echo "deb http://ftp.us.debian.org/debian stretch main contrib" >> /etc/apt/sources.list# Generate the APT cacheENV DEBIAN_FRONTEND noninteractiveRUN apt-get update \&& apt-get install -y apt-utils wget# Install the LEAD dependenciesRUN 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-selectionsRUN apt-get install -y \fontconfig ttf-mscorefonts-installer# Install wkhtmltopdfRUN wget -q https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.debRUN apt install -y --allow-unauthenticated \./wkhtmltox_0.12.5-1.stretch_amd64.debRUN ldconfig# Clean up APT cacheRUN rm -rf /var/lib/apt/lists/*# Delete the temp filesWORKDIR /appRUN rm -rf /tempEXPOSE 80# Copy and deploy applicationCOPY --from=build-env /app/core/out .ENTRYPOINT ["dotnet", "DocumentService.dll"]
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\
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.
Once the Docker image can be run, use the following command:
docker run -p 30000:80 documentserviceThe -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.

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