Tutorial: How to run a full desktop environment on LXD

Here are script/steps I’ve used setup a full KDE desktop environment in a LXD container.

It works by configuring Xspice on the guest as the main display server and mounting the spice socket on the host, then it can be just connected with remote-viewer, similarly to how LXD connects to VM VGA displays.

Currently the setup is relatively complicated and requires patching some binaries in the container, so I’ve created a script that does everything needed and exports a local image that can be used to launch desktop containers more quickly. Here’s the script gist: LXD: Full Debian KDE desktop · GitHub

Example of how to use:

lxc init debian-kde-desktop-xspice kde
lxc config device add kde xspicesocket proxy bind=host listen=unix:/tmp/kde.unix connect=unix:/run/xspice/spice.unix uid=1000 gid=1000
lxc start kde
remote-viewer spice+unix:///tmp/kde.unix

The setup script will create a temporary instance that is used to build the patched binaries, then a second instance is used to build the image. TBH it is currently more complicated than necessary (it is possible to do this without patching logind and xspice).

The main reason I’m sharing this script is to see if it is viable to have lxc console --type=vga implemented for containers. The idea is to have most of the heavy lifting be done on the image building side. On LXD side, the only necessary change is automatically create the proxy device when a vga console is attached. @stgraber / @tomp


Currently the setup is relatively complicated and requires patching some binaries in the container

What an interesting concept indeed, but wouldn’t virtual machines work better in this case?

Depends on what you mean by “work better”. Virtual machines are more isolated than containers, but usually also perform worse.

With this containerized desktop setup, the performance is much better on lower end hardware, while providing a similar experience to virtual machine in how it provides a “desktop on a window”.

1 Like