I have a JavaFX Maven Project. Run I run the Jar file, a GUI pops open for the user. I am trying to run it from a Docker container. I'm using Ubuntu 16.04.
I keep getting this error:
Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it.
Here is my Docker file (using a solution from here).
FROM docker.io/java as firstStage
WORKDIR /workdir/
RUN /usr/sbin/useradd --comment Developer \
--home-dir /home/developer \
--non-unique --uid 1000 --user-group --system \
--shell /bin/bash developer && mkdir -p /home/developer
RUN chown -R developer:developer /home/developer && mkdir -p /opt/app && chown -R developer:developer /opt/app
RUN echo 'developer ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
USER developer
ENV HOME /home/developer
VOLUME /opt/app
FROM maven:3.5.0-jdk-8
COPY --from=firstStage /workdir/ .
COPY . /
RUN apt-get update && apt-get install -y --no-install-recommends openjfx && rm -rf /var/lib/apt/lists/* && mvn clean install && DISPLAY=localhost:0.0
CMD ["java","-jar","/target/CodeDemo-1.0-SNAPSHOT.jar"]
I've looked through plenty of other answers to this question, and here is what else I've tried:
Running CMD with -Djava.awt.headless=true
.
Trying the SO solution here where you run "xauth add" within the container. But xauth "is not found". So I tried adding RUN sudo apt-get install xauth
to the Dockerfile. When I tried to build, I got an error saying xauth wasn't found. I did the same thing with x11-apps
.
I thought maybe it wouldn't install because it couldn't be found on my host machine (just a random guess), but I can run xauth on my host machine.
The only other solutions I've seen involved Putty and ssh. I just want to run the Docker container on my computer, not ssh into another one. I also saw some answers about virtualization. Do I have to create a whole virtual machine to run one program? Or am I missing something?
Anyone have any suggestions?