在 Docker 容器中设置 IronOCR
IronOCR 现在完全支持 Docker,包括适用于 Linux 和 Windows 的 Azure Docker 容器。
为什么使用 Docker?
Docker 使开发人员能够轻松地将任何应用程序打包、发布和运行为轻量级、可移植、自给自足的容器,并且可以在几乎任何地方运行。
IronOCR 和 Linux 入门
如果您是第一次接触 Docker 与 .NET,我们推荐您阅读这篇关于设置 Docker 调试以及如何将其与 Visual Studio 项目集成的优秀文章。 https://docs.microsoft.com/en-us/visualstudio/containers/edit-and-refresh?view=vs-2019
我们也强烈建议您阅读我们的IronOCR Linux 设置和兼容性指南。
推荐的 Linux Docker 发行版
我们推荐下面最新的64位Linux操作系统用于IronOCR的"轻松配置"。
- Ubuntu 20
- Ubuntu 18
- Debian 11
- Debian 10 [目前是 Microsoft Azure 的默认 Linux 发行版]
我们建议使用微软官方的 Docker 镜像。 其他Linux发行版部分支持,但可能需要使用apt-get手动配置。 请参阅我们的" Linux 手动安装指南"。
本文档中包含适用于 Ubuntu 和 Debian 的 Docker 文件:
IronOCR Linux Docker 安装要点
使用我们的 NuGet 包
我们建议使用IronOCR NuGet包。 它在 Windows、macOS 和 Linux 系统上进行开发时均可正常工作。
Ubuntu Linux Dockerfiles
Ubuntu 20 with .NET 5
# 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"]
Ubuntu 20 with .NET 3.1 LTS
# 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"]
Ubuntu 18 with .NET 3.1 LTS
# 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
Debian 11 with .NET 5
# Use the base runtime image for Debian 11 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 11 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
# Use the base runtime image for Debian 11 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 11 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 with .NET 5
# 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
# 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-utils、libgdiplus 和 libc6-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-utils 和 libgdiplus,并使用微软的官方 .NET 5 Docker 镜像作为基础镜像。
IronOCR 能否在 Windows 的 Docker 环境中使用?
是的,可以在 Windows 的 Docker 环境中使用 IronOCR。此过程涉及使用 IronOcr NuGet 包并配置 Dockerfile 以包括必要的依赖项和针对 Windows 操作系统的配置。
using Docker 托管 .NET OCR 应用程序的好处是什么?
using Docker 托管 .NET OCR 应用程序可以实现轻松部署、更好的资源管理以及在不同环境中更大的可移植性。Docker 容器是自给自足的,确保应用程序无论在哪个环境中都能一致地运行。
Is manual configuration required for non-recommended Linux distributions in Docker?
是的,如果您使用推荐以外的 Linux 发行版(如 Ubuntu 20、Ubuntu 18、Debian 11、Debian 10),则可能需要使用 apt-get 进行手动配置。IronOCR 提供的“Linux 手动设置”指南提供了有关手动设置的指南。
Can I use IronOCR with Azure Docker Containers?
Yes, IronOCR is fully compatible with Azure Docker Containers, allowing you to deploy and run .NET OCR applications on both Linux and Windows platforms within the Azure ecosystem.
What is the best way to develop and debug Docker applications using IronOCR?
For those new to Docker with .NET, the documentation recommends resources from Microsoft on setting up Docker debugging and integration with Visual Studio projects. This approach facilitates a smoother development experience.
Are there any official Docker images recommended for IronOCR?
IronOCR recommends using Microsoft's Official Docker Images for running .NET applications. These images are designed to provide a high level of compatibility and performance for .NET-based applications.

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