在 Docker 容器中設定 IronOCR
想用 C# 進行圖片或 PDF 檔案的 OCR 處理嗎?
IronOCR 現已全面支援 Docker,包括適用於 Linux 和 Windows 的 Azure Docker 容器。
![]()
為何要使用 Docker?
Docker 讓開發人員能夠輕鬆地將任何應用程式打包、部署並以輕量級、可攜式且自給自足的容器形式運行,這種容器幾乎可以在任何地方執行。
IronOCR 與 Linux Primer
若您對 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 作業系統,以便"輕鬆設定"IronPDF。
- Ubuntu 20
- Ubuntu 18
- Debian 11
- Debian 10 [目前為 Microsoft Azure 的預設 Linux 發行版]
我們建議使用 Microsoft 的官方 Docker 映像檔。 其他 Linux 發行版部分受支援,但可能需要使用 apt-get 進行手動設定。 請參閱我們的"Linux 手動設定"指南。
本文件中包含適用於 Ubuntu 和 Debian 的可運作 Docker 檔案:
IronOCR Linux Docker 安裝要點
使用我們的 NuGet 套件
我們建議使用 IronOCR NuGet 套件。 本工具適用於 Windows、macOS 及 Linux 平台進行開發。
Install-Package IronOcr
Ubuntu Linux DockerFiles
![]()
Ubuntu 20 搭配 .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 搭配 .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 搭配 .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 搭配 .NET 5
# 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"]
搭載 .NET 3.1 LTS 的 Debian 11
# 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"]
搭載 .NET 5 的 Debian 10
# 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"]
搭載 .NET 3.1 LTS 的 Debian 10
# 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 程式庫)在 Docker 容器中部署 C# OCR 應用程式。您需要為 Docker 容器設定必要的套件,例如 apt-utils, libgdiplus, libc6-dev,並採用 Microsoft 官方的 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 環境中使用?
是的,IronOCR 可在 Windows 上的 Docker 環境中使用。此過程需使用 IronOcr NuGet 套件,並配置 Dockerfile 以包含 Windows 作業系統所需的依賴項及特定設定。
using Docker 來託管 .NET OCR 應用程式有哪些好處?
using Docker 來託管 .NET OCR 應用程式,可實現輕鬆部署、更佳的資源管理,並提升跨不同環境的移植性。Docker 容器具有自足性,確保應用程式無論部署於何處,皆能保持一致的運行表現。
在 Docker 中使用非推薦的 Linux 發行版時,是否需要手動配置?
是的,若您使用的 Linux 發行版並非推薦版本(Ubuntu 20、Ubuntu 18、Debian 11、Debian 10),您可能需要使用 apt-get。IronOCR 提供的「Linux 手動設定」指南中,有相關的手動設定指引。
IronOCR 是否提供任何影像預處理功能?
IronOCR 包含用於提升 OCR 精準度的影像預處理功能,例如雜訊消除、旋轉校正及對比度調整。
IronOCR 能否用於雲端應用程式?
確實,IronOCR 可部署於雲端環境,使其適用於需要 OCR 功能的網路應用程式與服務。
如何使用 IronOCR 提升 OCR 結果的準確性?
若要提升 IronOCR 的 OCR 準確度,請確保輸入影像品質優良、使用適當的語言套件,並善用該程式庫的影像預處理功能。

