LinuxでIronPdf.Linuxを動かす:セットアップガイド
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
小型のDockerイメージを作成する方法
1. 実行時にパッケージをインストールする
サイズを縮小する 1 つの方法は、Docker イメージのビルド時ではなく、実行時に apt-get コマンドを実行することです。
- Dockerfile から
apt-getコマンドを削除します。 - IronPDF を初期化する前、またはドキュメントをレンダリングする前に、
Installation.LinuxAndDockerDependenciesAutoConfig = true;を設定します。 - アプリケーションが、
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.
2. IronPdf.Slimを使用
また、IronPdf.dllのみを含め、必要なファイルを実行時にダウンロードすることも選択できます。
- プロジェクトからIronPdf.Linux(およびその他のIronPdf)NuGetパッケージを削除し、IronPdf.Slimを追加します。
- IronPDF を初期化する前、またはドキュメントをレンダリングする前に、
Installation.AutomaticallyDownloadNativeBinaries = true;を設定します。 - Dockerfile がアプリケーションの作業ディレクトリ全体に対する読み取りおよび書き込み権限を付与していることを確認します (例:
RUN chmod +rwx /app/runtimes/linux-x64/native/IronCefSubprocessをRUN 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'
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
- アプリケーションディレクトリが書き込み可能/実行可能であることを確認します:
RUN chmod +rwx /app/
1と2の両方のポイントを利用する非常にスリムなDockerイメージは、サイズを約500MBから約200MBに削減するはずです。
可能であれば、スリムなデプロイメントを選ばない場合に最高のパフォーマンスが得られることを知っておいてください。
一部のコンテナ化された環境およびクラウド環境は永続的ではないため、依存関係を再度ダウンロードしたり、apt-get コマンドを再度実行したりする必要があり、これには数分かかる場合があります。
しかし、開発者の中にはデプロイメントのサイズに厳しい要件がある場合も理解しています。

