0

I have the following Dockerfile:

FROM adoptopenjdk/openjdk11
COPY target/VanatoareaDeDiamante.jar VanatoareaDeDiamante.jar
ENTRYPOINT ["java", "-jar", "/VanatoareaDeDiamante.jar"]

And docker-compose.yml:

services:
  game:
    image: 'game'
    build:
      context: .
    ports:
      - 5000:5000
    container_name: game
    depends_on:
      - postgresdb

  postgresdb:
    image: postgres:14
    container_name: database
    restart: always
    command:
      -p 5433
    environment:
      POSTGRES_DB: piu_project
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    ports:
      - 5433:5433

And it is a java GUI application which I want to run on a container. When I compose this up I get:

game          | Exception in thread "Thread-0" java.awt.HeadlessException:
game          | No X11 DISPLAY variable was set, but this program performed an operation which requires it.
game          |         at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:208)
game          |         at java.desktop/java.awt.Window.<init>(Window.java:548)
game          |         at java.desktop/java.awt.Frame.<init>(Frame.java:423)
game          |         at java.desktop/javax.swing.JFrame.<init>(JFrame.java:224)
game          |         at PIUGame.GameWindow.GameWindow.BuildGameWindow(GameWindow.java:34)
game          |         at PIUGame.Game.InitGame(Game.java:47)
game          |         at PIUGame.Game.run(Game.java:83)
game          |         at java.base/java.lang.Thread.run(Thread.java:829)

Some ideas?

Rain03
  • 41
  • 1
  • 7
  • A container doesn't usually have access to the host hardware, and running a GUI application in a container is tricky. Can you run the application directly on the host? If you're on a native-Linux host, [Can you run GUI applications in a Linux Docker container?](https://stackoverflow.com/questions/16296753/can-you-run-gui-applications-in-a-linux-docker-container) describes the long list of required bind mounts and environment variables. – David Maze Dec 10 '21 at 10:54

1 Answers1

0

You need to build your image with a base image that support GUI (X11) like this one.

gohm'c
  • 13,492
  • 1
  • 9
  • 16
  • I tried adding FROM jlesage/baseimage-gui:alpine-3.6 RUN add-pkg xterm in Dockerfile but still the same exception – Rain03 Dec 10 '21 at 09:36
  • `RUN add-pkg xterm` is an example, you don't really need it. Can you post your Dockerfile to your question. – gohm'c Dec 10 '21 at 09:42