Adding IronPDF to an Existing Docker Container

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

IronPDF for .NET Standard 現在全面支持 Docker,包括適用於 Linux 和 Windows 的 Azure Docker 容器。

您是否希望將 IronPDF 作為單獨的 Docker 容器部署? 了解更多關於 IronPDFEngine 教程指南

class="container-fluid">
class="row">
class="col-md-2"> Docker Logo
class="col-md-2"> Azure Logo
class="col-md-2"> Linux Logo
class="col-md-2"> AWS Logo
class="col-md-2"> Windows Logo

為什麼在 Azure 上使用 Docker?

除了優秀的企業級擴展性,Azure 上的 Docker 容器比普通 Web 應用享有更多權限。這便於渲染 SVG 字體,因為系統對 GDI+ 圖形的訪問已啟用。

IronPDF 和 Linux 入門

如果您對 Docker 與 .NET 不熟悉,我們推薦此優秀文章:設定 Docker 調試並集成到 Visual Studio 項目

我們也強烈建議您閱讀我們的 IronPDF Linux 設置和兼容性指南

推薦的 Linux Docker 發行版

我們推薦以下最新的 64 位 Linux 操作系統,以便 "輕鬆配置" IronPDF。

我們推薦使用微軟的 官方 .NET Docker 映像。 其他 Linux 發行版部分支持,但可能需要手動配置。 請參見我們的 "Linux 手動設置" 指南。

IronPDF Linux Docker 安裝

使用 Linux 優化的 NuGet 包

We recommend using the IronPdf.Linux NuGet package instead of the regular IronPdf package to save disk space and avoid assets being downloaded when you start your Docker instance. 不用擔心,它仍可在 Windows 或 macOS 上開發時使用 - 它只是對 Linux 進行了優化。

Install-Package IronPdf.Linux

Another solution is to simply add IronPdf.Native.Chrome.Linux on top of the regular IronPdf NuGet package.

Install-Package IronPdf.Native.Chrome.Linux

避免自動依賴安裝

許多用戶報告稱,在 Linux 和 Docker 上將 LinuxAndDockerDependenciesAutoConfig 設置為 false 後效果更佳。 這是因為在您的 Docker 文件中,前置條件已經由 apt-get 類型的包管理器安裝。

// Disable automatic configuration of Linux and Docker dependencies
IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = false;
// Disable automatic configuration of Linux and Docker dependencies
IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = false;
' Disable automatic configuration of Linux and Docker dependencies
IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = False
$vbLabelText   $csharpLabel

禁用 GPU 加速

Linux Docker 容器通常無法訪問 GPU。 GPU 加速默認情況下是禁用的。 如果您已啟用 ChromeGpuModes.Enabled,我們強烈建議您在 Docker 部署時禁用它:

// Disable GPU acceleration for Docker environments
IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled;
// Disable GPU acceleration for Docker environments
IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled;
' Disable GPU acceleration for Docker environments
IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled
$vbLabelText   $csharpLabel

Ubuntu Linux Docker 文件

class="container-fluid">
class="row">
class="col-md-2"> Docker Logo
class="col-md-2"> Ubuntu Logo

帶有 .NET 8 的 Ubuntu 22

Ubuntu 22 with .NET 7

Ubuntu 20 with .NET 6

Ubuntu 20 with .NET 5

Ubuntu 20 with .NET 3.1 LTS

Ubuntu 18 with .NET 3.1 LTS

Debian Linux Docker Files

Docker Logo
Debian Logo

Debian 12 with .NET 8

Debian 11 with .NET 7

Debian 11 with .NET 6

Debian 11 with .NET 5

Debian 11 with .NET 3.1 LTS

Debian 10 with .NET 5

Debian 10 with .NET 3.1 LTS

Alpine Linux Docker Files

Running IronPDF on Alpine Linux is not supported. We wish we could but we can't. Frankly, we like Alpine and hope this project continues and grows. As of 2023, Alpine still uses outdated "musl" C language libraries that do not allow chromium developers to fully support this OS yet.

Using Alpine Docker with IronPdfEngine in .NET 6

IronPDF provides a container image containing all IronPDF functionalities. This enables projects running on Alpine to access IronPD functionalities by connecting to the IronPdfEngine container.

Step 1: Pull and Run IronPDF Engine Docker Image

Execute the following commands in your terminal to pull and run the IronPDF Engine Docker image:

# Pull the IronPDF Engine Docker Image
docker pull ironsoftwareofficial/ironpdfengine
# Pull the IronPDF Engine Docker Image
docker pull ironsoftwareofficial/ironpdfengine
SHELL
# Run the IronPDF Engine Docker container
docker run -d -p 33350:33350 ironsoftwareofficial/ironpdfengine
# Run the IronPDF Engine Docker container
docker run -d -p 33350:33350 ironsoftwareofficial/ironpdfengine
SHELL

Step 2: Set Up Console App

Create a new console application targeting .NET 6. Install the IronPdf.Slim NuGet package using the NuGet Package Manager.

Windows Docker File

Docker Logo
Windows Logo

Windows Docker Containers are becoming increasingly popular on Azure, as they offer higher levels of performance and scalability and give developers more permissions to configure instances.

IronPDF will actually perform more attractive text rendering within a Docker container (Windows or Linux) on Azure due to higher levels of access to graphics library and the virtual graphics card.

The article 'Visual Studio Container Tools for Docker' is a really great get-started guide.

This is an example Windows container Dockerfile for .NET Core 3.1

Windows Server 2019 .NET 6.0

Pre-configured Windows containers include all the necessary dependencies for running IronPDF.

請注意Note that these containers are not intended for BUILDING .NET applications, but rather for RUNNING them.

Visit the Docker repository to explore additional pre-configured images for running IronPDF.

常見問題解答

如何將 .NET 庫集成到 Docker 容器中進行 PDF 生成?

您可以使用 IronPDF,這是一個 .NET 庫,通過使用微軟的官方 Docker 圖像和適用於 Linux 的 IronPdf.Linux NuGet 套件,或適用於 Windows 環境的預配置 Windows Docker 容器,將其集成到 Docker 容器中。

使用 Docker 容器進行 Azure 上的 PDF 操作有什麼好處?

在 Azure 上使用 Docker 容器進行 PDF 操作提供了增強的企業級擴展性和比常規網絡應用程序更多的許可權。此設置非常適合啟用諸如通過 GDI+ 圖形訪問的 SVG 字體渲染等高級功能。

哪些 Linux 發行版最適合在 Docker 中運行 .NET PDF 庫?

最合適的 Linux 發行版包括 Ubuntu 18/20/22、Debian 10/11、CentOS 8 和 Amazon AWS Linux 2,它們提供了直接的配置和兼容性。

如何優化 .NET PDF 庫在 Linux Docker 容器中的性能?

要優化性能,請使用 IronPdf.Linux 套件,禁用自動依賴安裝,並通過配置 IronPdf.Installation.ChromeGpuModeIronPdf.Engines.Chrome.ChromeGpuModes.Disabled 關閉 GPU 加速。

IronPDF 能夠在 Docker 容器中的 Alpine Linux 上運行嗎?

IronPDF 由於不兼容的 'musl' 庫,無法本地支持 Alpine Linux。若要在 Alpine Linux 上使用 IronPDF,請考慮通過 IronPdfEngine Docker 容器運行它。

使用預配置 Docker 容器的目的是什麼?

預配置 Docker 容器提供運行 IronPDF 所需的所有依賴,確保高性能和高擴展性,這在像 Azure 這樣的平台上部署時特別有益。

如何為 Docker 中的 .NET 應用程序配置 .NET PDF 庫?

通過將它與 Linux 和 Windows Docker 容器集成,可以為 Docker 中的 .NET 應用程序配置 IronPDF,從而在微服務架構中啟用穩健的 PDF 功能。

部署 .NET 庫在 Docker 的推薦設置步驟有哪些?

推薦的步驟包括使用優化的 Linux 套件如 IronPdf.Linux、禁用自動依賴安裝以及預先初始化 IronPDF 以防止 Docker 環境中的運行時延遲。

如何在運行 .NET 6.0 的 Windows Server 2019 Docker 容器中設置 .NET PDF 庫?

通過使用包含所有必要依賴和配置的預配置 Dockerfile,可以在 Windows Server 2019 Docker 容器中設置 .NET PDF 庫以運行 IronPDF 與 .NET 6.0。

為什麼在 Docker 設置中禁用 .NET 庫的 GPU 加速?

為 IronPDF 在 Docker 中禁用 GPU 加速可以通過避免環境中圖形資源有限時可能存在的問題來實現更平滑的部署和性能。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

準備好開始了嗎?
Nuget 下載 16,154,058 | 版本: 2025.11 剛剛發布