IronPdf.Linux
Linux 版 IronPdf 约 280MB (包括 IronPdf 代码和整个 Chrome 浏览器).Docker 映像大约为 500MB。
Chrome 浏览器还需要一些基本软件包,这些软件包因 Linux 发行版而异。大多数 Linux 发行版都已安装了这些软件包,因为 Linux 上的各种应用程序和库都会用到它们。
不过,如果你使用的是裸机发行版,则需要安装必要的 Linux 软件包才能让 Chrome 浏览器在 Linux 上运行。
注:为了方便调试,可以设置这些:
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
如何制作更小的 Docker 映像
1.运行时安装软件包
减少体积的一种方法是在运行时而不是在构建 docker 镜像时运行 apt-get
命令:
1.删除 Docker 文件中的 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.
2.使用 IronPdf.Slim
您也可以选择_only_include IronPdf.dll,并在运行时下载所需的文件。
移除 IronPdf.Linux (和任何其他 IronPdf) nuget 软件包(s) 并将 IronPdf.Slim
- 在初始化 IronPdf 或渲染文档前设置
Installation.AutomaticallyDownloadNativeBinaries = true;
3.确保你的 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'
3.结论
总之,要缩小初始容器尺寸:
- 使用 IronPdf.Slim NuGet 软件包
- 配置 IronPdf
Installation.LinuxAndDockerDependenciesAutoConfig = true;
Installation.AutomaticallyDownloadNativeBinaries = true;
- 确保应用程序目录可写/可执行
RUN chmod +rwx /app/
利用第 1 点和第 2 点的超薄 Docker 镜像应能将大小从 ~500MB 减少到 ~200MB。
可能的话,如果不选择超薄部署,您将看到最佳性能。
某些容器化和云环境是不持久的,因此可能需要偶尔重新下载依赖项,或再次运行 apt-get
命令,最多需要几分钟时间!
不过,我们理解,有些开发人员可能对其部署的规模有严格要求。