Setting up IronOCR in Docker Containers

This article was translated from English: Does it need improvement?
Translated
View the article in English

想要用 C#OCR 图像或 Pdf 文件吗?

IronOCR 现在完全支持 Docker,包括适用于 Linux 和 Windows 的 Azure Docker Containers。

Docker Linux AWS Windows

为什么使用 Docker? Docker 使开发人员能够将任何应用程序作为轻量级、可移植、自给自足的容器轻松打包、运输和运行,几乎可以在任何地方运行。

IronOCR 和 Linux 入门

我们还强烈建议您阅读我们的[IronOCR Linux 设置和兼容性指南](/csharp/ocr/how-to/tesseract-ocr-setup-linux-ubuntu-debian/)。

推荐的 Linux Docker 发行版

IronOCR Linux Docker 安装要点使用我们的 NuGet 软件包 Linux Ubuntu ### 使用 .NET 5 的 Ubuntu 20. ```dockerfile # Use the base runtime image for Ubuntu 20 with .NET runtime FROM mcr.microsoft.com/dotnet/runtime:5.0-focal AS base WORKDIR /app # Install necessary packages RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev # Use the base development image for Ubuntu 20 with .NET SDK FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build WORKDIR /src # Restore NuGet packages COPY ["Example/Example.csproj", "Example/"] RUN dotnet restore "Example/Example.csproj" # Build the project COPY . . WORKDIR "/src/Example" RUN dotnet build "Example.csproj" -c Release -o /app/build # Publish the project FROM build AS publish RUN dotnet publish "Example.csproj" -c Release -o /app/publish # Run the application FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "Example.dll"] ``` ### 采用 .NET 3.1 LTS 的 Ubuntu 20. ```dockerfile # Use the base runtime image for Ubuntu 20 with .NET runtime FROM mcr.microsoft.com/dotnet/runtime:3.1-focal AS base WORKDIR /app # Install necessary packages RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev # Use the base development image for Ubuntu 20 with .NET SDK FROM mcr.microsoft.com/dotnet/sdk:3.1-focal AS build WORKDIR /src # Restore NuGet packages COPY ["Example/Example.csproj", "Example/"] RUN dotnet restore "Example/Example.csproj" # Build the project COPY . . WORKDIR "/src/Example" RUN dotnet build "Example.csproj" -c Release -o /app/build # Publish the project FROM build AS publish RUN dotnet publish "Example.csproj" -c Release -o /app/publish # Run the application FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "Example.dll"] ``` ### 采用 .NET 3.1 LTS 的 Ubuntu 18. ```dockerfile # Use the base runtime image for Ubuntu 18 with .NET runtime FROM mcr.microsoft.com/dotnet/runtime:3.1-bionic AS base WORKDIR /app # Install necessary packages RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev # Use the base development image for Ubuntu 18 with .NET SDK FROM mcr.microsoft.com/dotnet/sdk:3.1-bionic AS build WORKDIR /src # Restore NuGet packages COPY ["Example/Example.csproj", "Example/"] RUN dotnet restore "Example/Example.csproj" # Build the project COPY . . WORKDIR "/src/Example" RUN dotnet build "Example.csproj" -c Release -o /app/build # Publish the project FROM build AS publish RUN dotnet publish "Example.csproj" -c Release -o /app/publish # Run the application FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "Example.dll"] ``` ## Debian Linux DockerFiles Docker Linux Debian ### Debian 11 与 .NET 5 ```dockerfile # Use the base runtime image for Debian 10 with .NET runtime FROM mcr.microsoft.com/dotnet/aspnet:5.0-bullseye-slim AS base WORKDIR /app # Install necessary packages RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev # Use the base development image for Debian 10 with .NET SDK FROM mcr.microsoft.com/dotnet/sdk:5.0-bullseye-slim AS build WORKDIR /src # Restore NuGet packages COPY ["Example/Example.csproj", "Example/"] RUN dotnet restore "Example/Example.csproj" # Build the project COPY . . WORKDIR "/src/Example" RUN dotnet build "Example.csproj" -c Release -o /app/build # Publish the project FROM build AS publish RUN dotnet publish "Example.csproj" -c Release -o /app/publish # Run the application FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "Example.dll"] ``` ### Debian 11 with .NET 3.1 LTS ```dockerfile # Use the base runtime image for Debian 10 with .NET runtime FROM mcr.microsoft.com/dotnet/aspnet:3.1-bullseye-slim AS base WORKDIR /app # Install necessary packages RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev # Use the base development image for Debian 10 with .NET SDK FROM mcr.microsoft.com/dotnet/sdk:3.1-bullseye-slim AS build WORKDIR /src # Restore NuGet packages COPY ["Example/Example.csproj", "Example/"] RUN dotnet restore "Example/Example.csproj" # Build the project COPY . . WORKDIR "/src/Example" RUN dotnet build "Example.csproj" -c Release -o /app/build # Publish the project FROM build AS publish RUN dotnet publish "Example.csproj" -c Release -o /app/publish # Run the application FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "Example.dll"] ``` ### Debian 10 与 .NET 5 ```dockerfile # Use the base runtime image for Debian 10 with .NET runtime FROM mcr.microsoft.com/dotnet/runtime:5.0 AS base WORKDIR /app # Install necessary packages RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev # Use the base development image for Debian 10 with .NET SDK FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build WORKDIR /src # Restore NuGet packages COPY ["Example/Example.csproj", "Example/"] RUN dotnet restore "Example/Example.csproj" # Build the project COPY . . WORKDIR "/src/Example" RUN dotnet build "Example.csproj" -c Release -o /app/build # Publish the project FROM build AS publish RUN dotnet publish "Example.csproj" -c Release -o /app/publish # Run the application FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "Example.dll"] ``` ### Debian 10 with .NET 3.1 LTS ```dockerfile # Use the base runtime image for Debian 10 with .NET runtime FROM mcr.microsoft.com/dotnet/runtime:3.1 AS base WORKDIR /app # Install necessary packages RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev # Use the base development image for Debian 10 with .NET SDK FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build WORKDIR /src # Restore NuGet packages COPY ["Example/Example.csproj", "Example/"] RUN dotnet restore "Example/Example.csproj" # Build the project COPY . . WORKDIR "/src/Example" RUN dotnet build "Example.csproj" -c Release -o /app/build # Publish the project FROM build AS publish RUN dotnet publish "Example.csproj" -c Release -o /app/publish # Run the application FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "Example.dll"] ```

常见问题解答

如何在 Docker 容器中部署 C# OCR 应用程序?

您可以通过使用 IronOCR,在 Docker 容器中部署 C# OCR 应用程序,IronOCR 是一个与 Docker 集成的 C# OCR 库。您需要设置包含必要包的 Docker 容器,如 apt-utilslibgdipluslibc6-dev,并使用微软的官方 Docker 镜像以实现最佳性能。

哪些操作系统最适合在 Docker 中运行 IronOCR?

为了在 Docker 中运行 IronOCR,推荐使用最新的 64 位 Linux 发行版,如 Ubuntu 20、Ubuntu 18、Debian 11 和 Debian 10,因为它们提供了简单的配置和支持。

如何在 Azure Docker 容器上配置 IronOCR?

要在 Azure Docker 容器上配置 IronOCR,您需要按照与其他 Docker 环境相同的步骤进行操作。使用 IronOcr NuGet 包,设置推荐的 Linux 发行版,并确保在您的 Dockerfile 中包含所有必要的依赖项。

在 Docker 中使用 .NET 5 设置 IronOCR 的步骤是什么?

在 Docker 中使用 .NET 5 设置 IronOCR,您需要创建一个 Dockerfile 安装 IronOcr NuGet 包,添加所需的包如 apt-utilslibgdiplus,并使用微软的官方 .NET 5 Docker 镜像作为基础镜像。

IronOCR 能否在 Windows 的 Docker 环境中使用?

是的,可以在 Windows 的 Docker 环境中使用 IronOCR。此过程涉及使用 IronOcr NuGet 包并配置 Dockerfile 以包括必要的依赖项和针对 Windows 操作系统的配置。

使用 Docker 托管 .NET OCR 应用程序的好处是什么?

使用 Docker 托管 .NET OCR 应用程序可以实现轻松部署、更好的资源管理以及在不同环境中更大的可移植性。Docker 容器是自给自足的,确保应用程序无论在哪个环境中都能一致地运行。

非推荐的 Linux 发行版在 Docker 中是否需要手动配置?

是的,如果您使用推荐以外的 Linux 发行版(如 Ubuntu 20、Ubuntu 18、Debian 11、Debian 10),则可能需要使用 apt-get 进行手动配置。IronOCR 提供的“Linux 手动设置”指南提供了有关手动设置的指南。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 5,044,537 | 版本: 2025.11 刚刚发布