IronPdf.Linux

IronPdf for Linux is about 280MB (including both IronPdf code and the entire Chrome browser). Docker images are around 500MB.

Chrome also requires some basic packages which vary based on your Linux distribution. Most Linux distributions have these packages installed already, as they are used by various applications and libraries on Linux.

However, if you're using a barebones distributions, you will need to install the Linux packages necessary to get Chrome running on Linux.

Note: In order to make debugging easier, you can set these:

IronPdf.Logging.Logger.EnableDebugging = true;
IronPdf.Logging.Logger.LogFilePath = "Default.log";
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
IronPdf.Logging.Logger.EnableDebugging = true;
IronPdf.Logging.Logger.LogFilePath = "Default.log";
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
IronPdf.Logging.Logger.EnableDebugging = True
IronPdf.Logging.Logger.LogFilePath = "Default.log"
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All
VB   C#

How to Make a Smaller Docker Image

1. Installing Packages at run-time

One way to reduce size is to run apt-get commands at runtime, rather than when building the docker image:

  1. Remove apt-get commands from your Dockerfile
  2. Set Installation.LinuxAndDockerDependenciesAutoConfig = true; before initializing IronPdf or rendering a document
  3. Ensure your application is executed with sufficient permissions to run apt-get commands

Note: Your first initialization will be slower as the apt-get commands must finish before rendering your first document, and this process will be repeat every time you have to re-deploy the image Note: you should see console/log entries indicating successful package installs:

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. Use IronPdf.Slim

You can also choose to _only _include IronPdf.dll and download the necessary files at runtime.

  1. remove IronPdf.Linux (and any other IronPdf) nuget package(s) from your project, and add IronPdf.Slim
  2. set Installation.AutomaticallyDownloadNativeBinaries = true; before initializing IronPdf or rendering a document
  3. Ensure your dockerfile grands read and write permissions to the entire working directory of your application (e.g. change RUN chmod +rwx /app/runtimes/linux-x64/native/IronCefSubprocess to RUN chmod +rwx /app/)

Note: your first initialization will be slower as the nuget package downloads and is extracted before rendering your first document, and this process will be repeat every time you have to re-deploy the image Note: you should see console/log entries indicating a successful download and extraction:

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. Conclusion

In summary, to reduce initial container size:

  • Use the IronPdf.Slim NuGet package
  • Configure IronPdf
Installation.LinuxAndDockerDependenciesAutoConfig = true;
    Installation.AutomaticallyDownloadNativeBinaries = true;
  • Ensure application directory is writable/executable

RUN chmod +rwx /app/

A very slim Docker image utilizing both points 1 and 2 should reduce the size from ~500MB to ~200MB.

If possible, you will see the best performance if you do NOT opt for a slim deployment.

Some containerized and cloud environments are not persistent and thus may have to occasionally re-download dependencies, or run the apt-get commands again, taking up to a couple of minutes!

However, we understand that some developers may be subject to strict size requirements for their deployments.