LinuxでIronPdf.Linuxを動かす:セットアップガイド
IronPDF for Linuxのサイズは約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. 実行時にパッケージをインストールする
サイズを縮小する一つの方法は、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コマンドを再度実行したりする必要が生じることがあり、その処理には最大で数分かかる場合があります!
しかし、開発者の中にはデプロイメントのサイズに厳しい要件がある場合も理解しています。

