[lxc-users] Basic X11 access in an lxd container

Dan Kegel dank at kegel.com
Sun May 15 01:13:28 UTC 2016

Has anyone translated
https://www.stgraber.org/2014/02/09/lxc-1-0-gui-in-containers/ to lxd

I've been playing around a bit with lxd, trying to run
xeyes inside the container, against the host's X11 server.

I set up my containers with macvlan, so I can't cheat
and use ssh to start xeyes; I'd like to use lxc exec.
So I tried:

$ lxc launch images:ubuntu/xenial/amd64 blort
$ lxc exec blort -- apt install x11-apps strace
$ lxc exec blort -- env DISPLAY=:0 xeyes

This fails, of course.  To make sure I knew why, I did
$ lxc exec blort -- env DISPLAY=:0 strace -o log xeyes
$ lxc exec blort -- cat log

This output roughly what I expected:
connect(3, {sa_family=AF_LOCAL, sun_path=@"/tmp/.X11-unix/X0"}, 20) =
-1 ECONNREFUSED (Connection refused)

Many lxc articles talk about sharing that path using e.g.
lxc.mount.entry = /tmp/.X11-unix tmp/.X11-unix none bind,ro,optional,create=dir
(The ro is there to keep the container from deleting the host's socket; see
https://bbs.archlinux.org/viewtopic.php?id=200704 )

$ lxc config device add blort x11-unix disk source=/tmp/.X11-unix
path=/tmp/.X11-unix readonly=true

Now xeyes fails with "No protocol specified", which is progress.
I'll try solving that after dinner :-)

More information about the lxc-users mailing list