简体   繁体   English

在 Docker 上运行“ProcessBuilder.start”失败

[英]Running "ProcessBuilder.start" on Docker fails

Install the libreoffice package in your Dcoker container, I'm trying to convert a JAVA application from Excel to a PDF file, but an error occurs. Install the libreoffice package in your Dcoker container, I'm trying to convert a JAVA application from Excel to a PDF file, but an error occurs. (The container is running on Google Cloud Run.) (容器在 Google Cloud Run 上运行。)

The Dockerfile is below. Dockerfile 如下。

FROM maven:3.8-jdk-11

RUN apt-get -y update
RUN apt-get -y install libreoffice
RUN mvn package

FROM adoptopenjdk/openjdk11:alpine-jre
CMD ["java", "-jar", "/app.jar"]

The java code running in the container is below.在容器中运行的 java 代码如下。

ProcessBuilder builder = new ProcessBuilder("/bin/sh", "-c", "soffice --headless -convert-to pdf --outdir '/out' '/out/file.xlsx'");
Process process = builder.start();

The error message that is output is as follows. output的错误信息如下。

line 1: soffice:not found

After installing the package in the Dockerfile, when I executed the which command, "usr/bin/libreoffice" existed, so I think the path is correct.在Dockerfile中安装package后,当我执行which命令时,“usr/bin/libreoffice”存在,所以我认为路径是正确的。 (I may be wrong.) (我可能错了。)

I think that there is a lack of information because I am a Docker beginner, I kindly thank you.我认为缺少信息,因为我是 Docker 初学者,谢谢。

The error says that /bin/sh does not know where the binary soffice is.错误说/bin/sh不知道二进制soffice在哪里。 The "soffice" binary must be on the PATH for /bin/sh . “soffice”二进制文件必须在/bin/sh的 PATH 上。 Launch a shell and check with which soffice , you may be able to fix your shell profile to include the correct PATH directories for soffice before your code will work:启动 shell 并检查which soffice ,您可能能够修复您的 shell 配置文件以包含 soffice 的正确 PATH 目录,然后您的代码才能工作:

ProcessBuilder builder = new ProcessBuilder("/bin/sh", "-c", "soffice --headless -convert-to pdf --outdir '/out' '/out/file.xlsx'");

But if you know the fully qualified path to the soffice binary you should be able to eliminate the use of sub-process shell and separate the command line arguments:但是,如果您知道 soffice 二进制文件的完全限定路径,您应该能够消除使用子进程 shell 并分离命令行 arguments:

String soffice = "/full/path/to/soffice"; // eg /usr/lib/libreoffice/program/soffice.bin
// Check with:
System.out.println(soffice +" exists: "+new File(soffice).exists());
ProcessBuilder builder = new ProcessBuilder(soffice, "--headless", "-convert-to pdf", "--outdir", "/out", "/out/file.xlsx");

If "soffice" is in the PATH provided to your JVM, then launch without sub-process shell and path ought to work.如果“soffice”在提供给您的 JVM 的 PATH 中,则在没有子进程 shell 的情况下启动并且路径应该可以工作。 You may be able to check which soffice before launching your Java application to see if this may work:您可以在启动 Java 应用程序之前检查which soffice ,看看这是否可行:

String soffice = "soffice"; 
ProcessBuilder builder = new ProcessBuilder(soffice, "--headless", "-convert-to pdf", "--outdir", "/out", "/out/file.xlsx");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure 应用服务无法启动 w/ Azure 容器注册表拉取 - Docker 容器 - 找不到文件 - 与 Docker 集线器一起使用 - Azure App Service Fails to Start w/ Azure Container Registry Pull - Docker Container - Can not Find File - Works with Docker Hub 运行多容器 Docker 的 AWS BeanStalk 环境无法启动并显示 Health: Severe - AWS BeanStalk environment running multi-container Docker fail to start with Health: Severe 运行时导出的 VertexAI TabularModel model_warm_up 失败 docker - Exported VertexAI TabularModel model_warm_up fails when running docker Firebase 模拟器启动失败 - Firebase Emulator Fails To Start Lambda Docker 图像未运行 - Lambda Docker Image Not Running 作为服务运行 Docker - 环境变量 - Running Docker as a Service - Environment Variables Docker 部署总是失败——巨大的容器大小 - Docker deployment always fails - massive container size AWS ECS 无法在 Fargate 上启动 windows - AWS ECS fails to start windows on Fargate AWS Cloudshell 无法启动 docker 服务 - AWS Cloudshell unable to start docker service Docker 容器在本地运行但在 Cloud Run 上失败 - Docker container runs locally but fails on Cloud Run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM