Running IronPDF on Linux: Setup Guide

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

Linux用のIronPdfは約280MBです(IronPdfのコードとChromeブラウザ全体を含む)。 Dockerイメージは約500MBです。

Chromeには、Linuxディストリビューションに応じて異なる基本的なパッケージが必要です。 多くのLinuxディストリビューションはすでにこれらのパッケージがインストールされています。これらはさまざまなアプリケーションやライブラリで使用されるためです。

しかし、最低限のディストリビューションを使用している場合は、ChromeをLinux上で動作させるために必要なLinuxパッケージをインストールする必要があります。

注: デバッグを容易にするため、次の設定をすることができます。

// Enable detailed debugging for IronPdf
IronPdf.Logging.Logger.EnableDebugging = true;

// Specify the log file path
IronPdf.Logging.Logger.LogFilePath = "Default.log";

// Set the logging mode to capture all log data
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
// Enable detailed debugging for IronPdf
IronPdf.Logging.Logger.EnableDebugging = true;

// Specify the log file path
IronPdf.Logging.Logger.LogFilePath = "Default.log";

// Set the logging mode to capture all log data
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
' Enable detailed debugging for IronPdf
IronPdf.Logging.Logger.EnableDebugging = True

' Specify the log file path
IronPdf.Logging.Logger.LogFilePath = "Default.log"

' Set the logging mode to capture all log data
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All
$vbLabelText   $csharpLabel

小型のDockerイメージを作成する方法

1. 実行時にパッケージをインストールする

サイズを削減する方法の1つは、dockerイメージを構築する際ではなく、実行時にapt-getコマンドを実行することです。

  1. Dockerfileからapt-getコマンドを削除します。
  2. IronPdfを初期化するか、ドキュメントをレンダリングする前にInstallation.LinuxAndDockerDependenciesAutoConfig = true;を設定します。
  3. アプリケーションがapt-getコマンドを実行するのに十分な権限で実行されるようにします。

注: 最初の初期化時には、apt-getコマンドが最初のドキュメントをレンダリングする前に完了しなければならないため、初期化が遅くなります。このプロセスは、イメージを再デプロイするたびに繰り返されます。

注: コンソール/ログに、パッケージのインストールが正常に完了したことを示すエントリが表示されるはずです。

Executing command 'apt install -y libnss3' in '/app/bin/Debug/netcoreapp3.1/runtimes/linux-x64/native'
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  libnspr4
The following NEW packages will be installed:
  libnspr4 libnss3
0 upgraded, 2 newly installed, 0 to remove and 9 not upgraded.
Executing command 'apt install -y libnss3' in '/app/bin/Debug/netcoreapp3.1/runtimes/linux-x64/native'
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  libnspr4
The following NEW packages will be installed:
  libnspr4 libnss3
0 upgraded, 2 newly installed, 0 to remove and 9 not upgraded.
SHELL

2. IronPdf.Slimを使用

また、IronPdf.dllのみを含め、必要なファイルを実行時にダウンロードすることも選択できます。

  1. プロジェクトからIronPdf.Linux(およびその他のIronPdf)NuGetパッケージを削除し、IronPdf.Slimを追加します。
  2. IronPdfを初期化するかドキュメントをレンダリングする前にInstallation.AutomaticallyDownloadNativeBinaries = true;を設定します。
  3. Dockerfileがアプリケーションの作業ディレクトリ全体に読み書き権限を付与するようにします(例: RUN chmod +rwx /app/runtimes/linux-x64/native/IronCefSubprocessRUN chmod +rwx /app/ に変更します)。

注: 最初の初期化時には、NuGetパッケージのダウンロードと展開が最初のドキュメントをレンダリングする前に行われるため遅くなります。このプロセスは、イメージを再デプロイするたびに繰り返されます。

注: コンソール/ログに、ダウンロードと展開が正常に完了したことを示すエントリが表示されるはずです。

Downloading NuGet package from 'https://www.nuget.org/api/v2/package/IronPdf.Native.Chrome.Linux/2023.1.11387'
Extracting package contents '/app/bin/Debug/netcoreapp3.1/IronPdf.Native.Chrome.Linux.2023.1.11387.nupkg/runtimes/linux-x64/native' to '/app/bin/Debug/netcoreapp3.1/runtimes/linux-x64/native'
Successfully deployed NuGet package 'IronPdf.Native.Chrome.Linux' to '/app/bin/Debug/netcoreapp3.1/runtimes/linux-x64/native'
Successfully located 'IronInterop' at '/app/bin/Debug/netcoreapp3.1/runtimes/linux-x64/native'
Downloading NuGet package from 'https://www.nuget.org/api/v2/package/IronPdf.Native.Chrome.Linux/2023.1.11387'
Extracting package contents '/app/bin/Debug/netcoreapp3.1/IronPdf.Native.Chrome.Linux.2023.1.11387.nupkg/runtimes/linux-x64/native' to '/app/bin/Debug/netcoreapp3.1/runtimes/linux-x64/native'
Successfully deployed NuGet package 'IronPdf.Native.Chrome.Linux' to '/app/bin/Debug/netcoreapp3.1/runtimes/linux-x64/native'
Successfully located 'IronInterop' at '/app/bin/Debug/netcoreapp3.1/runtimes/linux-x64/native'
SHELL

3. 結論

_初期コンテナサイズを削減する_ための要約:

  • IronPdf.Slim NuGetパッケージを使用します。
  • IronPdfを設定します:
// Set installation options for Linux and Docker environments
Installation.LinuxAndDockerDependenciesAutoConfig = true;
Installation.AutomaticallyDownloadNativeBinaries = true;
// Set installation options for Linux and Docker environments
Installation.LinuxAndDockerDependenciesAutoConfig = true;
Installation.AutomaticallyDownloadNativeBinaries = true;
' Set installation options for Linux and Docker environments
Installation.LinuxAndDockerDependenciesAutoConfig = True
Installation.AutomaticallyDownloadNativeBinaries = True
$vbLabelText   $csharpLabel
  • アプリケーションディレクトリが書き込み可能/実行可能であることを確認します:
RUN chmod +rwx /app/

1と2の両方のポイントを利用する非常にスリムなDockerイメージは、サイズを約500MBから約200MBに削減するはずです。

可能であれば、スリムなデプロイメントを選ばない場合に最高のパフォーマンスが得られることを知っておいてください。

一部のコンテナ化されたクラウド環境は永続的ではなく、依存関係を再ダウンロードするかapt-getコマンドを再実行する必要がある場合がありますが、これにかかる時間は数分に及ぶことがあります。

しかし、開発者の中にはデプロイメントのサイズに厳しい要件がある場合も理解しています。

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はいいですか?
Nuget ダウンロード 16,154,058 | バージョン: 2025.11 ただ今リリースされました