How can you run GUI applications in a Docker container?
Are there any images that set up vncserver
or something so that you can - for example - add an e
Here's a lightweight solution that avoids having to install any X
server, vnc
server or sshd
daemon on the container. What it gains in simplicity it loses in security and isolation.
It assumes that you connect to the host machine using ssh
with X11
forwarding.
In the sshd
configuration of the host, add the line
X11UseLocalhost no
So that the forwarded X server port on the host is opened on all interfaces (not just lo
) and in particular on the Docker virtual interface, docker0
.
The container, when run, needs access to the .Xauthority
file so that it can connect to the server. In order to do that, we define a read-only volume pointing to the home directory on the host (maybe not a wise idea!) and also set the XAUTHORITY
variable accordingly.
docker run -v $HOME:/hosthome:ro -e XAUTHORITY=/hosthome/.Xauthority
That is not enough, we also have to pass the DISPLAY variable from the host, but substituting the hostname by the ip:
-e DISPLAY=$(echo $DISPLAY | sed "s/^.*:/$(hostname -i):/")
We can define an alias:
alias dockerX11run='docker run -v $HOME:/hosthome:ro -e XAUTHORITY=/hosthome/.Xauthority -e DISPLAY=$(echo $DISPLAY | sed "s/^.*:/$(hostname -i):/")'
And test it like this:
dockerX11run centos xeyes