-1

enter image description here

When I try to run the java swing image getting the "Headless Exception error"

DockerFile:

FROM openjdk:8

COPY requiredlibararies requiredlibraries

COPY myjar.jar myjar.jar CMD ["java", "-Djava.awt.headless=true", "-jar", "myjar.jar"]

2
  • 1
    You need an X11 server running on the host and connected to the docker instance. Commented Dec 21, 2020 at 3:36
  • Thanks, I have installed the vcxsrv in my machine and used docker run -it --rm -e DISPLAY=${ipaddress} imagname /bin/bash Commented Dec 22, 2020 at 13:46

1 Answer 1

0

The container has to interact with the Mouse Keyboard and display of the your host machine to execute the GUI. Installed X11 server on the host machine and then communicated the container with the x11 server of my host machine.

  1. Installed vcxsrv-64.1.20.8.1.installer
  2. Started the Xlaunch
  3. docker run -it --rm -e DISPLAY=${ipaddress of hostmachine} image/bin/bash
Sign up to request clarification or add additional context in comments.

1 Comment

Note that X11 security is an afterthought, and if you can do this, you have it most likely turned it off. Be absolutely certain that vcxsrv is not listening on a port exposed to others (configure your firewall and/or vcxsrv) or anyone can point to your machineand do nasty stuff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.