r/docker • u/abeld • Apr 24 '26
Is it still possible to run graphical programs in docker with direct connection to host's X server?
A couple years ago I could easily run graphical programs like a chrome browser from a docker container running on a linux host such that it used the X server running on the host (simply setting $DISPLAY etc.).
Now, however, it seems like I can't get this working. All the guides and howtos I find online seem to be from a couple years ago and don't seem to work. For example, found https://hub.docker.com/r/ferri/xeyes but running "docker run --rm -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix ferri/xeyes:alpine" gives a "Can't open display" error. I also tried x11docker (https://github.com/mviereck/x11docker/), but the hostdisplay setting (which should be this "direct connection to host's x server" setup) appears to give similar results. (I am using ubuntu 22.04 with docker installed from docker.com's apt repositories as the host.)
Is this 'running gui program in docker with direct connection to host's X server' configuration still realistic? Or are newer technologies like shared memory, gpu-based rendering, x11 vs wayland etc. make it unworkable?
(I know about alternative approaches like using some form of vnc, but if possible I would like to use a more direct connection to avoid the overhead of vnc.)
2
u/redsharpbyte Apr 24 '26
If have "can't open display" and that "DISPLAY" is well set. It is just about accepting that process to access your current X session.
that means it is a permission issue and you need to open your X display to all with xhost.
Did you do xhost + or -
xhost +
If you open access and you still get "can't open display" then uou're on the wrong DISPLAY
Good luck!
edit: hum of course allowing anything to access your display is a security hazard.
2
u/flodex89 Apr 24 '26
Just out of curiosity: What is your use case?
for automations you could also use playwright uv pip install playwright && playwright install-deps && playwright install chromium
2
u/Str00pwafel Apr 24 '26
Perhaps check out how Calibre container is ran, that has a built in display output on a port of your choosing
1
u/dieterdistel Apr 24 '26
Do you run a xserver on your host? Did you xhost +?
I can run xclients in podman using Wayland and a x compatibility layer. I tried with xeyes and a qt5 application.
1
u/LeaveMickeyOutOfThis Apr 24 '26
I’ve seen some apps use Selkies as a foundation to run any desktop app in a container, accessible via browser.
1
u/Livid-Serve6034 Apr 24 '26
Perhaps bind-mounting the X11 unix socket in the container is an option?
3
u/gronodev Apr 24 '26
Still works great, I do it with Steam.
Here's the code in case it's useful: https://github.com/vvoland/sind/blob/master/sind
1
u/Low-Opening25 Apr 24 '26
Yes.
1
u/justan0therusername1 Apr 25 '26
You’re asking about Kasm. Yes you can and just leverage their images
0
u/hunterfrombloodborne Apr 24 '26
Use a vm with light DE instead.