IronPDF 开始 在Docker中托管和使用IronPdfEngine Run IronPDF as a Remote Container Curtis Chau 已更新:九月 23, 2025 Download IronPDF NuGet 下载 DLL 下载 Windows 安装程序 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article This article was translated from English: Does it need improvement? Translated View the article in English IronPdfEngine 是一个独立的服务,可以处理 PDF 的创建、写入、编辑和读取。 IronPDF Docker 准备运行与兼容 IronPDF 版本 (v2023.2.x 及更高版本) 的 docker 服务。 这将帮助开发人员消除与 IronPDF 的部署问题。 为什么将 IronPDF 作为其自己的容器运行是个好主意 IronPDF 要运行需要 Chrome 和 Pdfium 二进制文件,这些文件的文件大小很大(数百 MB)。 它还要求在机器上安装多个依赖项。 通过这种方法,您的客户端只会占用一小部分大小(以 MB 计)。 避免部署问题 配置环境/容器以正确包含所有依赖项可能具有挑战性。 使用 IronPDF Docker 容器意味着 IronPDF 预装且保证可用,避免所有部署和依赖项的麻烦。 版本 IronPDF Docker 标签基于 IronPdfEngine 本身的版本。 它与 IronPDF 产品的版本不相同。 每个 IronPDF 版本将有其关联的 IronPdfEngine 版本。 版本号必须匹配 IronPDF Docker 版本。 例如,IronPDF for Java 版本 2023.2.1 需要 IronPdfEngine 版本 2023.2.1。 您不能使用不匹配的 IronPdfEngine 和 IronPDF 版本。 <hr 如何使用 IronPDF Docker 安装IronPDF 将IronPdf.Slim Nuget包添加到您的项目。 https://www.nuget.org/packages/IronPdf.Slim/ 注意:IronPdf、IronPdf.Linux 和 IronPdf.MacOs 包含 IronPdf.Slim。 为了减小应用程序的大小,我们建议仅安装 IronPdf.Slim。 包 IronPdf.Native.Chrome.xxx 不再使用,因此可以从项目中删除。 确定所需的容器版本 默认情况下,IronPDF for Docker 版本将匹配 NuGet 上当前的 IronPDF 版本。 您可以使用以下代码手动检查版本: :path=/static-assets/pdf/content-code-examples/how-to/ironpdfengine-docker-version.cs string ironPdfEngineVersion = IronPdf.Installation.IronPdfEngineVersion; Dim ironPdfEngineVersion As String = IronPdf.Installation.IronPdfEngineVersion $vbLabelText $csharpLabel 设置 IronPDF for Docker 容器 无需使用 Docker Compose 根据上一步的版本运行 docker 容器。 必须安装 Docker。 设置 访问 https://hub.docker.com/r/ironsoftwareofficial/ironpdfengine 拉取最新的 ironsoftwareofficial/ironpdfengine 镜像 docker pull ironsoftwareofficial/ironpdfengine docker pull ironsoftwareofficial/ironpdfengine SHELL 或者拉取特定版本(推荐) docker pull ironsoftwareofficial/ironpdfengine:2025.3.6 docker pull ironsoftwareofficial/ironpdfengine:2025.3.6 SHELL 运行 ironsoftwareofficial/ironpdfengine 容器。 此命令将在后台创建容器并使用端口 33350 运行 docker run -d -p 33350:33350 -e IRONPDF_ENGINE_LICENSE_KEY=MY_LICENSE_KEY ironsoftwareofficial/ironpdfengine:2025.3.6 docker run -d -p 33350:33350 -e IRONPDF_ENGINE_LICENSE_KEY=MY_LICENSE_KEY ironsoftwareofficial/ironpdfengine:2025.3.6 SHELL 使用 Docker Compose 关键是设置一个允许 IronPdfEngine 和您的应用程序相互识别的 Docker 网络。 设置 'depends_on' 以确保 IronPdfEngine 在您的应用程序启动之前 已启动。 设置 通过创建 docker-compose.yml 文件来开始。使用以下模板设置 Docker Compose 文件: version: '3.6' services: myironpdfengine: container_name: ironpdfengine image: ironsoftwareofficial/ironpdfengine:latest ports: - '33350:33350' networks: - ironpdf-network myconsoleapp: container_name: myconsoleapp build: # enter YOUR project directory path here context: ./MyConsoleApp/ # enter YOUR dockerfile name here, relative to project directory dockerfile: Dockerfile networks: - ironpdf-network depends_on: myironpdfengine: condition: service_started networks: ironpdf-network: driver: 'bridge' 在您的应用程序(myconsoleapp)中将 IronPdfEngine 的地址设置为“myironpdfengine:33350” 运行 docker compose docker compose up --detach --force-recreate --remove-orphans --timestamps docker compose up --detach --force-recreate --remove-orphans --timestamps SHELL 连接到 IronPdfEngine 运行您的 IronPDF 代码; 您的应用程序现已与 Docker 中的 IronPdfEngine 通信! :path=/static-assets/pdf/content-code-examples/how-to/ironpdfengine-docker-use.cs using IronPdf; using IronPdf.GrpcLayer; // Configure for Docker container var config = IronPdfConnectionConfiguration.Docker; config.Host = "localhost"; IronPdf.Installation.ConnectToIronPdfHost(config); // Use IronPDF ChromePdfRenderer renderer = new ChromePdfRenderer(); PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF Docker!<h1>"); pdf.SaveAs("ironpdf.pdf"); Imports IronPdf Imports IronPdf.GrpcLayer ' Configure for Docker container Private config = IronPdfConnectionConfiguration.Docker config.Host = "localhost" IronPdf.Installation.ConnectToIronPdfHost(config) ' Use IronPDF Dim renderer As New ChromePdfRenderer() Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF Docker!<h1>") pdf.SaveAs("ironpdf.pdf") $vbLabelText $csharpLabel <hr 连接类型 根据所需的连接类型,您可以分配多个 IronPdfConnectionType。 以下是可用属性的列表: LocalExcutable:用于连接在您的本地机器上运行可执行程序的 IronPdfEngine “服务器”,我们使用此选项。 一个快速示例是 WinForm 开票应用程序,它在本地生成 PDF 而不依赖于云服务。 Docker:此选项应在尝试连接本地或云中的 Docker 容器时使用。 RemoteServer:此选项用于云中的 IronPdfEngine。 通过 HTTP 或 HTTPS 协议连接到云托管(例如,Docker)的 IronPdfEngine 实例。 请注意,由于这是连接到远程服务器,因此需要完整的 URL(包括 HTTP 或 HTTPS 协议)。 Custom:为了完全控制和自定义连接,您可以使用此选项。 此选项使用用户自定义的 Grpc.Core.ChannelBase 而不是上述定义的其他选项。 开发人员可以通过创建新的 Grpc.Core.Channel 对象或使用 Grpc.Net.Client.GrpcChannel.ForAddress(System.String) 创建新通道以获得对 gRPC 通道的自定义和完全控制。 .NET Framework 与 NetFrameworkChannel 对于 .NET Framework,由于 gRPC 在 .NET Framework 项目中以不同方式工作,我们需要不同的设置。 为了让此方法工作,请确保已安装 Grpc.Core NuGet 包。 我们将使用从 Grpc.Core.ChannelBase 派生的自定义 gRPC 通道进行此特定设置。 让我们来看这个示例,我们将实现连接通道以使用 IronPDFEngine 创建和保存 PDF。 [{t:(由于 gRPC 在 .NET Framework 项目中以不同方式工作,如果以下代码不起作用,请尝试删除地址中的 <http> 或 <https> 前缀。)}] [{w:(请注意,在此情况下需要使用 pdf.Dispose。)}] :path=/static-assets/pdf/content-code-examples/how-to/ironpdfengine-docker-use-grpc.cs using IronPdf; // This code demonstrates how to use IronPdf with gRPC in a .NET Framework application. // 1. Configure connection to use local IronPdfEngine executable var config = IronPdf.GrpcLayer.IronPdfConnectionConfiguration.Executable; // 2. Connect to the IronPDF host with the executable configuration IronPdf.Installation.ConnectToIronPdfHost(config); // 3. Create a PDF renderer instance ChromePdfRenderer renderer = new ChromePdfRenderer(); // 4. Render HTML string as PDF document PdfDocument pdf = renderer.RenderHtmlAsPdf("Hello world"); // 5. Save the PDF to disk pdf.SaveAs("output.pdf"); // 6. Clean up , this is needed to work pdf.Dispose(); IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel 使用 WithCustomChannel 的替代方法 一种替代方法是利用 IronPdf.GrpcLayer 提供的 WithCustomChannel 方法。 WithCustomChannel 接受两个参数,第一个是customChannel,即用户自定义的 gRPC 通道,第二个是metadata。 metadata 参数是可选的,默认为 null。 :path=/static-assets/pdf/content-code-examples/how-to/ironpdfengine-docker-use-grpc-alt.cs using IronPdf; using IronPdf.GrpcLayer; using Grpc.Core; // 1. Create custom gRPC channel (.NET Framework style) var channel = new Channel("123.456.7.8:80", ChannelCredentials.SecureSsl); // 2. (Optional) Add metadata headers if needed var metadata = new Metadata { { "Authorization", "Bearer your_token_here" } }; // 3. Configure IronPDF with custom channel var config = IronPdfConnectionConfiguration.WithCustomChannel(channel, metadata); IronPdf.Installation.ConnectToIronPdfHost(config); // 4. Generate PDF var renderer = new ChromePdfRenderer(); PdfDocument pdf = renderer.RenderHtmlAsPdf("Hello world"); // 5. Save the PDF to disk pdf.SaveAs("output.pdf"); // 6. Clean up , this is needed to work pdf.Dispose(); IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel <hr 在 AWS ECS 上部署 IronPdfEngine 前提条件 拉取 IronPdfEngine Docker 镜像。 这在上面的 Setup IronPDF for Docker Container 中已提及。 拥有访问 ECS 的 AWS 账户。 设置 创建 ECS 集群。 请根据此指南来使用控制台为 Fargate 和 External 启动类型创建集群。 创建任务定义。 请根据此指南使用控制台创建任务定义。 推荐设置: AWS Fargate 推荐至少 1 个 vCPU 和 2 GB 的 RAM。 根据您的工作负载,如果您正在处理包含超过 10 页的 PDF 或经历高负载请求,请选择更高的层级。 Network mode: awsvpc Port mappings: { "containerPort": 33350, "hostPort": 33350, "protocol": "tcp", "appProtocol": "grpc" } Image URI: 指向我们任意 IronPdfEngine。 例如 "ironsoftwareofficial/ironpdfengine:2024.1.20" (来自 DockerHub) AWS 权限 和 网络配置由您自己决定 推荐启用 Amazon CloudWatch。 (启用日志记录) 如果您希望在同一任务定义中部署您的应用程序容器,则需要设置容器启动顺序。 运行任务定义。 您可以选择以任务或服务形式来运行任务定义。 请根据此指南使用控制台创建服务。 推荐设置: 启动类型:AWS Fargate 公共 IP: 开启以进行测试,生产时请选择关闭。 安全和 AWS 网络配置由您自己决定。 享受吧! IronPdfEngine docker 在您的 AWS 上运行! [{i:(不支持水平扩展。 请参阅 IronPdfEngine 限制 了解更多信息。)}] <hr 在 Azure 容器实例上部署 IronPdfEngine 前提条件 拉取 IronPdfEngine Docker 镜像。 这在上面的 Setup IronPDF for Docker Container 中已提及。 Azure 账户 设置 创建一个 Azure 容器。 请根据此快速入门指南使用 Azure 门户部署容器实例。 推荐设置: 镜像来源: 其他注册表 镜像: ironsoftwareofficial/ironpdfengine:2024.1.20 (来自 Docker Hub) OS 类型: Linux 大小: 至少 1 个 vCPU 和 2 GiB 的内存,或更高 端口: TCP 端口 33350 享受吧! IronPdfEngine docker 在您的 Azure 容器实例上运行! [{i:(不支持水平扩展。 请参阅 IronPdfEngine 限制 了解更多信息。)}] <hr 在 AWS ECR 公共资源库中获取 IronPdfEngine 先决条件 必须安装 Docker。 设置 访问 https://gallery.ecr.aws/v1m9w8y1/ironpdfengine 拉取 v1m9w8y1/ironpdfengine 镜像 docker pull https://gallery.ecr.aws/v1m9w8y1/ironpdfengine docker pull https://gallery.ecr.aws/v1m9w8y1/ironpdfengine SHELL 或者拉取特定版本(推荐) docker pull https://gallery.ecr.aws/v1m9w8y1/ironpdfengine:2023.12.6 docker pull https://gallery.ecr.aws/v1m9w8y1/ironpdfengine:2023.12.6 SHELL 运行 ironpdfengine 容器。 此命令将在后台创建容器并使用端口 33350 运行 docker run -d -p 33350:33350 ironsoftwareofficial/ironpdfengine docker run -d -p 33350:33350 ironsoftwareofficial/ironpdfengine SHELL 了解如何通过导航到 "更新代码以使用 IronPdfEngine" 部分来配置 IronPdf 客户端以利用 IronPdfEngine。 <hr 从市场获取 IronPdfEngine 为了帮助您快速入门,我们已在 Azure 和 AWS 市场设置了 IronPdfEngine。 Azure 市场 class="content-img-align-center"> class="center-image-wrapper"> 设置 访问 IronPDF Docker Container on Azure Marketplace。 点击 “立即获取” 和 “继续”。 完成“基础”、“集群详细信息”和“应用程序详细信息”以创建 Kubernetes 服务。 一旦部署完成,导航到左侧栏选择 Kubernetes 资源> Run command。 执行以下命令: kubectl get services kubectl get services SHELL class="content-img-align-center"> class="center-image-wrapper"> 通过 EXTERNAL-IP 和 PORT(S) 的信息,您可以相应地配置 IronPDFEngine 连接。 :path=/static-assets/pdf/content-code-examples/how-to/pull-run-ironpdfengine-azure-marketplace.cs using IronPdf; using IronPdf.GrpcLayer; IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01"; IronPdfConnectionConfiguration configuration = new IronPdfConnectionConfiguration(); configuration.ConnectionType = IronPdfConnectionType.RemoteServer; configuration.Host = "http://48.216.143.233"; configuration.Port = 80; IronPdf.Installation.ConnectToIronPdfHost(configuration); ChromePdfRenderer renderer = new ChromePdfRenderer(); PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>"); pdf.SaveAs("output.pdf"); Imports IronPdf Imports IronPdf.GrpcLayer IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01" Dim configuration As New IronPdfConnectionConfiguration() configuration.ConnectionType = IronPdfConnectionType.RemoteServer configuration.Host = "http://48.216.143.233" configuration.Port = 80 IronPdf.Installation.ConnectToIronPdfHost(configuration) Dim renderer As New ChromePdfRenderer() Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>testing</h1>") pdf.SaveAs("output.pdf") $vbLabelText $csharpLabel AWS 市场 class="content-img-align-center"> class="center-image-wrapper"> 先决条件 必须安装 Docker。 必须安装并登录 AWS CLI。 设置 访问 IronPdfEngine on AWS marketplace。 点击 '继续订阅'。 接受条款。 class="content-img-align-center"> class="center-image-wrapper"> 继续配置。 class="content-img-align-center"> class="center-image-wrapper"> 拉取 ironpdfengine 镜像。 这一步会向您展示一个命令来拉取 ironpdfengine 镜像。 class="content-img-align-center"> class="center-image-wrapper"> 例如: aws ecr get-login-password \ --region us-east-1 | docker login \ --username AWS \ --password-stdin 000000000000.dkr.ecr.us-east-1.amazonaws.com CONTAINER_IMAGES="000000000000.dkr.ecr.us-east-1.amazonaws.com/iron-software/ironpdfengine:2024.1.15" for i in $(echo $CONTAINER_IMAGES | sed "s/,/ /g"); do docker pull $i; done aws ecr get-login-password \ --region us-east-1 | docker login \ --username AWS \ --password-stdin 000000000000.dkr.ecr.us-east-1.amazonaws.com CONTAINER_IMAGES="000000000000.dkr.ecr.us-east-1.amazonaws.com/iron-software/ironpdfengine:2024.1.15" for i in $(echo $CONTAINER_IMAGES | sed "s/,/ /g"); do docker pull $i; done SHELL 运行 ironpdfengine 容器。 此命令将在后台创建容器并使用端口 33350 运行. docker run -d -p 33350:33350 000000000000.dkr.ecr.us-east-1.amazonaws.com/iron-software/ironpdfengine:2024.1.15 docker run -d -p 33350:33350 000000000000.dkr.ecr.us-east-1.amazonaws.com/iron-software/ironpdfengine:2024.1.15 SHELL IronPdfEngine 的健康检查 检查您的 Docker 容器的健康状况对于确保在生产环境中的可靠性和可用性至关重要。 检查 IronPdfEngine Docker 容器的能力允许开发人员在服务失败时重启服务,增加资源以应对需求增加,并监控连续不断的应用。 要检查您的 IronPdfEngine 的健康状况,我们可以向同一 IronPdfEngine 端口(默认情况下为 33350)发送 gRPC 请求,以验证是否收到响应。 通过 gRPC 进行健康检查 IronPdfEngine 遵循标准 gRPC 健康检查模式,使用以下协议结构。 message HealthCheckRequest { string service = 1; // Name of the service to check (e.g., "IronPdfEngine") } 由于我们要检查 IronPdfEngine,我们将服务名称替换为 IronPdfEngine。 以下是使用 Postman 在 JavaScript 中发送 gRPC 请求到本地 IronPdfEngine 服务默认端口 33350 的示例。 class="content-img-align-center"> class="center-image-wrapper"> 从响应中可以看到,状态响应为 SERVING,表示服务正在运行中。 如果容器不健康,则状态响应为 NOT_SERVING。 使用 Kubernetes 设置进行健康检查 对于 Kubernetes 设置,我们可以使用以下方式检查服务是否健康。 livenessProbe: exec: command: - /bin/grpc_health_probe - -addr=:33350 - -rpc-timeout=5s livenessProbe: exec: command: - /bin/grpc_health_probe - -addr=:33350 - -rpc-timeout=5s YAML 常见问题解答 如何在Docker中使用C#将HTML转换为PDF? 您可以使用IronPDF的Docker设置在C#中将HTML转换为PDF。在Docker容器中部署IronPdfEngine,并使用诸如RenderHtmlAsPdf之类的方法来实现这一点。 在Docker中使用IronPdfEngine的好处有哪些? 在Docker中使用IronPdfEngine提供了一个预先安装的可靠环境,减少了依赖问题,并确保所有必要的组件,如Chrome和Pdfium二进制文件,均可用。 如何使用Docker Compose设置IronPdfEngine? 创建一个docker-compose.yml文件并定义服务和网络。使用depends_on指令确保IronPdfEngine在您的应用程序之前启动。 将IronPdfEngine部署到AWS ECS需要哪些步骤? 要在AWS ECS上部署,创建一个ECS集群,定义一个任务定义,并使用AWS Fargate进行资源分配。然后,运行您的任务或服务以启动IronPdfEngine。 如何从AWS ECR Public Gallery中获取IronPdfEngine? 访问AWS ECR Public Gallery,找到IronPdfEngine镜像,并按照提供的命令拉取并运行容器。 是否可以从Azure Marketplace使用IronPdfEngine? 是的,IronPdfEngine可在Azure Marketplace上获得。您可以按Marketplace页面上的设置说明部署Docker容器。 使用IronPdfEngine时应注意哪些限制? IronPdfEngine不支持水平扩展。在规划部署时需要考虑这一限制,以确保它满足您的应用程序需求。 如何高效处理Docker中的PDF生成和操作任务? 在Docker容器中部署IronPdfEngine,以高效管理PDF生成和操作任务,利用Docker的能力来处理依赖项并确保一致的环境。 在Azure Container Instances上部署IronPdfEngine的要求是什么? 要在Azure Container Instances上部署,请确保您有一个Azure帐户并拉取IronPdfEngine Docker镜像进行部署。 Curtis Chau 立即与工程团队聊天 技术作家 Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。 准备开始了吗? Nuget 下载 16,154,058 | 版本: 2025.11 刚刚发布 免费 NuGet 下载 总下载量:16,154,058 查看许可证