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.
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
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
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.
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.
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...
Docker daemon. Also known as the Docker Engine, the Docker daemon is a thin layer between the containers and the Linux kernel. The Docker daemon is the persistent runtime environment that manages application containers.
The easiest way to deploy a Dockerized application on a remote server is to transfer the application's image with docker pull and then use docker run . This runs the application in a container similar to how you'd do it in your development environment.
It's ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.
RUN. RUN creates a layer at build-time. Docker commits the state of the image after each RUN. RUN is often used to install packages into an image. In the example above, RUN apk update && apk upgrade tells Docker to update the packages from the base image.
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
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
Dont forget to remove -e DISPLAY=192.168.1.71:0.0
from your docker run command
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With