This tutorial shows how to set up the LEADTOOLS Document Service in a Docker container.
|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)|
|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);
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.
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
### Building the build environment image
FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build-env
# 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
# 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 \
# 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 \
# Clean up APT cache
RUN rm -rf /var/lib/apt/lists/*
# Delete the temp files
RUN rm -rf /temp
# Copy and deploy application
COPY --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
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 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.
This tutorial showed how to set up the LEADTOOLS Document Service in a Docker Container and run on local host.