不能在Docker上运行JavaFX应用超过几分钟 [英] Cannot run JavaFX app on docker for more than a few minutes

查看:96
本文介绍了不能在Docker上运行JavaFX应用超过几分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个用作单独Web应用程序的通信服务的应用程序.我有0个问题在泊坞窗化" Web应用程序,但事实证明该服务是一场噩梦.它基于JavaFX,并且可以由用户在配置文件中设置一个属性,该属性使得该属性不会初始化任何窗口,菜单,容器等.这种无头"模式(不确定是否真正无头...)有效地将服务应用程序变成了后台服务.首先,我还要说这个应用程序在Windows 10机器上运行时绝对完美,并且我已经将它部署在其他几台机器(所有未经过dockerized的机器上)都没有问题.

I developed an application used as a communication service for a separate web app. I had 0 issues "dockerizing" the web app but the service is proving to be a nightmare. It is based on JavaFX and there is a property that can be set by the user in the config file that makes it so the app does not initialize any windows, menus, containers, etc. This "headless" mode (not sure that is truly headless...) effectively turns the service app into a background service. Let me also preface this by saying that the app works absolutely flawlessly when run on my windows 10 machine and that i have deployed it on several other machines (all non-dockerized) with no issues.

这是我想出的dockerfile:

Here is the dockerfile i came up with :

FROM openjdk:13.0.1-slim
RUN apt-get update && apt-get install libgtk-3-0 libglu1-mesa -y && apt-get update
VOLUME /tmp
ADD Some_Service-0.0.1-SNAPSHOT.jar Some_Service-0.0.1-SNAPSHOT.jar
ADD lib lib
ADD config.properties config.properties
ENTRYPOINT ["java", "--module-path", "lib/javafx-sdk-13", "-jar", "Some_Service-0.0.1-SNAPSHOT.jar"]

然后我使用此命令来构建容器:

I then use this command to build the container :

docker run -t --name Some_Service -e DISPLAY=192.168.1.71:0.0 -e SERVICE_HOME= --link mySQLMD:mysql some_service

假设VcXsrv在我的PC上运行,则该应用程序可以正确启动,尽管它在首次启动时会给出以下警告:

Assuming VcXsrv is running on my PC, the app start correctly, although it does give these warnings when first starting :

libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
Prism-ES2 Error : GL_VERSION (major.minor) = 1.4

问题在于它只能工作2分钟左右.最终,容器出现此错误并崩溃:

The issue is that it only works for like 2 minutes. Eventually the container comes up with this error and crashes :

Gdk-Message: 15:28:54.770: java: Fatal IO error 11 (Resource temporarily unavailable) on X server 192.168.1.71:0.0.

我知道最初的消息是由于该容器没有NVidia驱动程序,但是回退到软件管道似乎可以正常工作.老实说,我不知道致命的IO错误可能是由什么引起的.我在运行docker的不同主机上尝试过,并且发生了相同的问题.

I understand the initial messages are due to the container having no NVidia driver but the fallback to the software pipeline seems to work fine. Honestly I have no idea what the fatal IO error could be caused by. I have tried on different hosts running docker and the same issue happens.

有什么办法解决这个问题吗?更好的是,您有什么主意如何使JavaFX应用程序真正变得无头,甚至不需要初始化任何东西?无头运行时,我使用JavaFX中的Tasks之类的任务,所以我不能只是不使用它...

Any idea how to fix this? Even better, any idea how to make a JavaFX app TRULY headless and not even require any of this stuff to be initialized? When running headless, i use Tasks and such which are part of JavaFX so I can't just not use it...

推荐答案

在容器中安装xvfb,这将创建一个虚拟屏幕. 更改为Docker文件:

Install xvfb in your container this create a virtual screen. change to Docker file:

FROM openjdk:13.0.1-slim
RUN apt-get update && apt-get install libgtk-3-0 libglu1-mesa xvfb -y && 
apt-get update
VOLUME /tmp
ADD Some_Service-0.0.1-SNAPSHOT.jar Some_Service-0.0.1-SNAPSHOT.jar
ADD lib lib
ADD config.properties config.properties
apt-get install xvfb
ENV DISPLAY=:99
ADD run.sh /run.sh
RUN chmod a+x /run.sh
CMD /run.sh 

在您的项目文件夹中添加新的bash脚本,并将其命名为"run.sh"

Add new bash Script in your project folder and name it "run.sh"

run.sh:

#!/bin/bash
#remove old 
rm /tmp/.X99-lock #needed when docker container is restarted
Xvfb :99 -screen 0 640x480x8 -nolisten tcp &
java --module-path lib/javafx-sdk-13 -jar Some_Service-0.0.1-SNAPSHOT.jar

别忘了从docker run命令中删除-e DISPLAY=192.168.1.71:0.0

Dont forget to remove -e DISPLAY=192.168.1.71:0.0 from your docker run command

这篇关于不能在Docker上运行JavaFX应用超过几分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆