I am having trouble running a Java GUI app from within a docker container so that it appears on my desktop, as xeyes does.
Here are the steps I'm taking:

I am logged into my physical machine in a Unity session and open up a terminal, running the commands:

root@prod:~# echo $DISPLAY 
root@prod:~# ls /tmp/.X11-unix/
X0  X1024

I then get onto a VPN and SSH into a host (named host-a).
I can run xeyes from within the host-a and the eyes appear on Unity, follow my mouse around, so X forwarding works.

a@host-a$ echo $DISPLAY
a@host-a$ sudo netstat -anutp | grep 60
tcp        0      0*               LISTEN      21988/6         
tcp        0      0*               LISTEN      22182/14        
tcp6       0      0 ::1:6010                :::*                    LISTEN      21988/6         
tcp6       0      0 ::1:6011                :::*                    LISTEN      22182/14

Within host-a, I then use docker to run image containing the Java app:

a@host-a$ sudo docker run --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -ti repo/image bash`

The output is:

root@7722f3167495:/# echo $DISPLAY

Then trying to the run the Java app gives:

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

I've tried setting DISPLAY to 10.0 also but same.
I note that only local machine prod contains the sockets in /tmp/.x11-unix. The container and host-a do not.

Any suggestions on why X session is not established would be greatly appreciated.

1 Answer 1


It's not likely to be possible this way

The X11 socket file is for local connection only and will only be accessible on your workstation. From there its TCP.

As you have used SSH with X11Forwarding to SSH into your server host-a it has created a tcp connection between your workstation and the server. This is TCP X11 display 'localhost:10' when you are on your server. And the SSH client on your workstation will forward traffic from there to your .X11 unix socket file. I'm not sure where the localhost:11 display is coming from but it is also related to the SSH forwarding. Did you do just one SSH hop, or two?

You may have more success, if you enable TCP listening directly on your workstation X server (remove '-nolisten tcp' flags and you might need to add '-listen tcp') then tell the docker container to use your workstation display directly

docker run .... -e DISPLAY=<workstation-ip-address>:0

However you'll then also likely have 'xauth' errors

You could use the xauth command to export an authentication token to your home directory on the server and then mount that as a docker volume to give the container access to the token, and either also set the XAUTHORITY environment variable in the docker command, to that exported xauth file, or else use xauth within the container to import the token.

I have an old sample docker container somewhere on gitbub that does this for running Azureus I'll see if I can find the link

Sometimes it is a lot easier to add a VNC server into the container, start your Java app within a vnc session in the container, and use vnc to connect to it from the workstation.

or on the docker host, you can run a vnc server and use docker '-net host' to share the host networking stack, and use DISPLAY=:5900 in the container, and connect to the VNC display host-a:0 from your workstation. That gets around needing to add VNC packages into your container

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .