java GUI inside docker container stuck on running container

145 Views Asked by At

I have the following dockerfile

# Set the base image to openjdk:8-jdk
FROM openjdk:8-jdk

# Set environment variables
ENV DISPLAY=:99

# Install required packages
RUN apt-get update && \
apt-get install -y \
curl \
uuid-runtime \
x11-apps \
xvfb \
libxtst6 && \
rm -rf /var/lib/apt/lists/*

# Set the working directory to /app
WORKDIR /app

# Create the properties directory and copy the jar file and properties file to the container
COPY merlin.jar ./
COPY ./properties/message.properties properties/

# Start Xvfb and the Java application
CMD ["sh", "-c", "Xvfb :99 -screen 0 1024x768x16 & \n\
java -jar -Dserver.address=0.0.0.0 -Dserver.port=8080 merlin.jar > /app/app.log"]

my file structure is directory: merlin.jar, dockerfile, properties folder containing message.properties file. This was needed since the jar file for some reason contains the file but still can't be found so I did the commands manually.

I can build my image just fine but when running it using docker run -it --rm -p 8080:8080 myapp the cli becomes stuck and unresponsive until I ctrl+C. the app.log gives no output. When executing the CMD ["sh", "-c", "Xvfb :99 -screen 0 1024x768x16 & ] and \n\ java -jar -Dserver.address=0.0.0.0 -Dserver.port=8080 merlin.jar > /app/app.log" seperately using commando: docker run -it --rm myapp /bin/bash it indicates the xvfb server works and is running. The second command however makes the cli freeze. I want that users with 0 technical skills can just download docker run this image and have the java GUI open for it's intended usage. The user shouldn't have to download anything else. No local x11 servers as they should be done in the dockerfile. I have been stuck on this for a bit now since I lack log information and have limited knowledge about this. Hope someone can assist, thanks in advance!

edit: I did manage to get it working with a locally setup xming server but i'd like this to work inside the docker container.

0

There are 0 best solutions below