android-studio-docker icon indicating copy to clipboard operation
android-studio-docker copied to clipboard

can't connect to X11 (Ubuntu 22.04.3 LTS)

Open Utopiah opened this issue 1 year ago • 8 comments

Failed to initialize graphics environment

java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.

(base) utopiah@r15-desktop4090:~/Prototypes/android-studio-docker$ echo $DISPLAY
:0

with in compose.yml having

       # Mount the proper locationm for x11 server if you are running this in native linux
      - /tmp/.X11-unix:/tmp/.X11-unix .
      - android_studio:/androidstudio-data
    environment:
      - DISPLAY=:0 # Set DISPLAY environment variable

Utopiah avatar Feb 27 '24 12:02 Utopiah

Same error on Ubuntu 23.10

Utopiah avatar Mar 01 '24 14:03 Utopiah

I tried xhost + or adding in $HOME/.bash_profile

JAVA_OPTIONS=-Djava.awt.headless=true
export JAVA_OPTIONS

but same result.

Utopiah avatar Mar 01 '24 14:03 Utopiah

The error tells you that you can't connect to the display server. Usually, the server listens on :0, but this could also be some other variable. What does your shell (not inside docker!) DISPLAY environment variable say?

Deadolus avatar Mar 04 '24 08:03 Deadolus

That's what I thought which is why I shared

echo $DISPLAY
:0

isn't it matching?

Utopiah avatar Mar 04 '24 08:03 Utopiah

Not sure if it makes a difference in that case but I run docker here as a user, not as root.

Utopiah avatar Mar 04 '24 08:03 Utopiah

Not sure if it makes a difference in that case but I run docker here as a user, not as root.

That should not make a difference. Make sure you are running x11, not wayland mabe? Maybe some problem with your .xauthority file not allowing access to the x11 server? Sorry can't help here, I am also no display server expert.

Deadolus avatar Mar 04 '24 08:03 Deadolus

Seems so :

fabien@fabien-CORSAIR-ONE-i160:~$ echo $XDG_SESSION_TYPE
x11

No worries I'll investigate https://stackoverflow.com/questions/44429394/x11-forwarding-of-a-gui-app-running-in-docker and report here!

Utopiah avatar Mar 04 '24 09:03 Utopiah

@Utopiah I assume you use wayland try running this in the terminal 'xhost + local:' works on gnome

@Deadolus maybe this can be added in the run.sh for wayland?

mihalycsaba avatar May 24 '24 13:05 mihalycsaba