在 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 作業系統,以便"輕鬆配置"IronPDF。
- 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 系統上進行開發時均可正常運作。
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"]Debian 11 及 .NET 3.1 LTS
# 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
# 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 及 .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 庫)在 Docker 容器中部署 C# OCR 應用程式。您需要使用必要的軟體包(例如apt-utils 、 libgdiplus和libc6-dev來配置 Docker 容器,並使用 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,該 Dockerfile 安裝 IronOcr NuGet 套件,新增所需的套件(如apt-utils和libgdiplus ,並使用 Microsoft 的官方 .NET 5 Docker 映像。
IronOCR 能否在 Windows 系統的 Docker 環境中使用?
是的,IronOCR 可以在 Windows 的 Docker 環境中使用。具體步驟包括使用 IronOcr NuGet 套件,並配置 Dockerfile,使其包含 Windows 作業系統特有的必要依賴項和配置。
使用 Docker 託管 .NET OCR 應用程式有哪些好處?
使用 Docker 託管 .NET OCR 應用程式可以簡化部署、更好地管理資源,並提高跨環境的可移植性。 Docker 容器是自包含的,確保應用程式無論部署在何處都能穩定運作。
對於 Docker 中非建議的 Linux 發行版,是否需要手動設定?
是的,如果您使用的是除推薦發行版(Ubuntu 20、Ubuntu 18、Debian 11、Debian 10)之外的 Linux 發行版,則可能需要使用apt-get進行手動設定。 IronOCR 提供的「Linux 手動設定」指南中提供了手動設定的指導。






