【问题标题】:running a process within docker在 docker 中运行进程
【发布时间】:2022-01-20 14:34:00
【问题描述】:

我使用 libreoffice 将 word 文档转换为 pdf 文档。 这个过程是 soffice.exe 或 linux 中的等价物。

这个进程通常位于:c:\program files\libreoffice\program\soffice.exe

在 iisexpress 中运行应用程序时,它可以完美运行,但不能在 docker 中运行。

我假设我需要打开一个条目,因为 docker 需要访问权限?

代码sn-p:

//convert word to pdf
                var convert = new ReportGenerator(LibreOfficeOptions.LibreOfficeWindows);
                convert.Convert(RootPath + viewModel.Invoices.First().InvoiceId + ".docx", RootPath + viewModel.Invoices.First().InvoiceId + ".pdf");
                Log.Information($"Invoice word document has been converted to pdf document!");
                return true;
            }
            catch (Exception ex)
            {
                Log.Error($"Exception has been thrown in the creation of the invoice final document: {ex.Message}");
                return false;
            }

【问题讨论】:

  • 它是否安装在您的容器中?你的基本图片是什么?
  • 我的电脑上没有安装 libre office,目前不是 docker 桌面。我的基本图像是 .net 5.0 sdk 或 Visual Studio 采用的任何图像
  • @DanielA.White 我可以只使用一个卷并将外部程序放在那里吗?
  • 基础镜像是一个 linux 镜像 - 所以你不能挂载一个 windows 卷并运行它。
  • @DanielA.White 这是真的,但在生产中它将是 linux。

标签: c# asp.net docker


【解决方案1】:

您需要在此处编写基于操作系统的条件才能使用相应的 libreoffice 二进制文件。

  1. 在您的代码中,检测当前操作系统并设置与检测到的操作系统相对应的进程路径和文档路径。 Windows (\) 和 Unix (/) 中的二进制路径和路径分隔符不同

  2. 在您的dockerfile 中添加安装 libreoffice 的步骤以获取最终映像。 Libreoffice Dockerfile。如果您有自己的私有存储库,则可以为 dotnet 运行时创建自己的自定义 docker 映像以包含 libreoffice,以避免增加项目构建时间。这会带来额外的维护,即在补丁发布后定期更新自定义 docker 映像。

【讨论】:

  • 感谢您提供的信息,我会调查的。目前我已经设置了一个卷并且它确实可以在这种情况下调用 soffice.exe 文件但它确实会失败。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-01
  • 1970-01-01
  • 2017-03-26
  • 1970-01-01
  • 2016-11-25
相关资源
最近更新 更多