从Docker映像运行JavaFX Spark应用程序时发生错误

时间:2019-12-05 12:06:33

标签: apache-spark javafx dockerfile

我正在尝试运行JavaFX SparkML应用程序的Docker映像。我可以创建一个映像,但是在运行该映像时,出现与JavaFX相关的错误。

这是我的第一个Docker映像,如果能为我指明正确的方向,我将不胜感激。我已经在线搜索并尝试了几种将JavaFX添加到我的docker镜像中的方法,但是我仍然遇到相同的错误!

我的Dockerfile:

# build
#FROM maven AS build

FROM maven:3.5.3-jdk-8 AS build
WORKDIR /usr/src/app
COPY pom.xml .

RUN apt-get update
RUN apt-get install -y --no-install-recommends openjfx && rm -rf /var/lib/apt/lists/*

# Install apt-utils
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y curl

# Install openjfx
#RUN apt-get update
#RUN apt-get install -y openjfx

RUN mvn -f /usr/src/app/pom.xml clean package

#RUN mvn -B -e -C -T 1C org.apache.maven.plugins:maven-dependency-plugin:3.1.1:go-offline
COPY . .
#RUN mvn -B -e -o -T 1C verify



# package without maven
FROM openjdk

COPY --from=build /usr/src/app/target/*.jar ./bda-1.0.0-SNAPSHOT.jar

RUN chmod 777 *.jar

EXPOSE 8080  
CMD ["java","-jar","./bda-1.0.0-SNAPSHOT.jar"] 

以及由此产生的错误:

Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:280)
        at com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:222)
        at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:260)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
        at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
        at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:94)
        at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)
        ... 1 more
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.RuntimeException: No toolkit found
        at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:272)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
        at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
        at java.base/java.lang.Thread.run(Thread.java:830)

1 个答案:

答案 0 :(得分:0)

JDK仍包含JavaFX。您的stacktrace包含JavaFX类。所以我想这不是您的实际问题。

泊坞窗映像不直接支持UI。它只是一个与本地桌面隔离的容器。

但是似乎可以将docker容器配置为使用本地X-Server渲染UI。我找到了以下示例:https://medium.com/@SaravSun/running-gui-applications-inside-docker-containers-83d65c0db110

基本上,您必须将所需的X-Server库安装到容器中并配置显示,网络和卷,以使其正常工作。