Is it possible to run xwindow in a container?

(Bob Goodwin) #1

Title of this post says it all. I have made a preliminary attempt but had no success yet. I did learn a little about container devices in the attempt so it wasn’t a total loss.

Best regards,
Bob G.


When you run a graphical (X11) application on a Linux distribution, you have on one part the client X11 libraries, and on the other the X11 server that will display the windows on a display.

The first part is quite easy; you can install, for example, firefox in a LXD container and this will pull in the necessary client X11 libraries. But when you are about to run this application, you need to choose where to show the application window, on which X11 server.

One option is to reuse your desktop’s X11 server. In that case, you would set up the container in a way that would give full access to the X11 server socket, and to the PulseAudio socket (for sound).
The easiest way to do so, is to follow this guide,

Specifically, you create here a LXD profile, and when you want to create such a GUI container, you have to launch it as follows:

lxc launch ubuntu:18.04 --profile default --profile gui myguicontainer

There are other more advanced options where you create a separate X11 server just for the container, therefore separating properly your desktop from the container applications.

Also, some users have tried to set up a system with no X11 server to run the only X11 server through a LXD container. It should be possible but I did not read about them finishing this effort.