Repository navigation
How to use in Docker on Linux
A big thank you to @fwaris for this guide.
It took me a while to get TesseractOCR running under Linux. For anyone looking to do the same, below is the Dockerfile I ended up with. Note that after adding all the dependencies to the image, the final part adds symlinks in the x64 directory to the leptonica and tesseract .so libraries.
FROM mcr.microsoft.com/dotnet/sdk:9.0.304-bookworm-slim AS base
RUN apt-get update && apt-get install -y --no-install-recommends
ca-certificates curl gnupg unzip wget libtesseract-dev libc6-dev libjpeg-dev
&& update-ca-certificates
&& rm -rf /var/lib/apt/lists/*
FROM base AS build
RUN apt-get update && apt-get install -y --no-install-recommends
git cmake build-essential
&& rm -rf /var/lib/apt/lists/*
RUN git clone --depth 1 --branch 1.85.0 https://github.com/DanBloomberg/leptonica.git /leptonica WORKDIR /leptonica RUN mkdir build WORKDIR /leptonica/build RUN cmake .. -DBUILD_SHARED_LIBS=ON RUN cmake --build . --config Release RUN cmake --install . --prefix /usr/local RUN ln -s /lib/x86_64-linux-gnu/libdl.so.2 /usr/lib/libdl.so RUN ldconfig
WORKDIR /src COPY src . WORKDIR /src/
RUN --mount=type=cache,target=/root/.nuget/packages
dotnet restore
RUN --mount=type=cache,target=/root/.nuget/packages
dotnet publish -c Release
-o /app --no-restore
FROM build AS final EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000 ENV HOME=/home
COPY --from=ext trainData/ ${HOME}/trainData/
WORKDIR /app
COPY --from=build /app . RUN ln -s /usr/local/lib/libleptonica.so ./x64/libleptonica-1.85.0.dll.so RUN ln -s /usr/lib/x86_64-linux-gnu/libtesseract.so ./x64/libtesseract55.dll.so
ENTRYPOINT ["dotnet", ""]