简体   繁体   中英

Java Swing GUI in a Centos 7 Docker container on a Windows Host

I am building a Docker image FROM centos:7 (I am flexible on the base Linux image) which will run a Java Swing application on a Windows 10 host. When attempting to run the Docker image, I get the following exception:

java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it.
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204) ~[?:1.8.0_302]
        at java.awt.Window.<init>(Window.java:536) ~[?:1.8.0_302]
        at java.awt.Frame.<init>(Frame.java:420) ~[?:1.8.0_302]
        at java.awt.Frame.<init>(Frame.java:385) ~[?:1.8.0_302]
        at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1763) ~[?:1.8.0_302]
        at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1838) ~[?:1.8.0_302]
        at javax.swing.JDialog.<init>(JDialog.java:272) ~[?:1.8.0_302]
        at javax.swing.JDialog.<init>(JDialog.java:206) ~[?:1.8.0_302]

Am I using the wrong Linux flavor or have I not configured it correctly? I would like the resulting image to be standalone and not require any additional software to be installed on the host machine. Is this possible?

So if you want your docker container to open a window on the windows machine, configure an X server ( https://teamdynamix.umich.edu/TDClient/47/LSAPortal/KB/ArticleDet?ID=1797 ) so it accepts connections, then tell the container by setting the environment variable DISPLAY how to connect to that X server.

Upon next start of the container the error should be gone or different.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM