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 コマンドの再実行が必要になる場合があります。これには最大で数分かかることがあります!
しかし、開発者の中にはデプロイメントのサイズに厳しい要件がある場合も理解しています。






