Is it possible to run xwindow in a container?

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.

Thank you for your response simos. It has taken a while to get back to this effort. I followed your link and although the CLI command examples were outdated, I was able to make sense of it enough to make some progress.

I’ve run into another snag. One of the example CLI entries using outdated syntax;
lxc config device add guiapps X0 disk path=/tmp/.X11-unix/X0 source=/tmp/.X11-unix/X0

I reinterpreted as;
sudo lxc-device -n my-gui-container add /tmp/.X11-unix/X0 /tmp/.X11-unix/X0
The response to this is;

Container my-gui-container is not running.
I then enter;

lxc-start -n my-gui-container

and the response is;

Container is already running.


Any idea how that happens?

Best regards,
Bob G.

Hi Bob!

There is LXC and there is LXD. You are using LXC while my tutorial is for LXD.

The commands that look like lxc-xxxxxx (as in lxc-start) are LXC.
The commands that look like lxc xxxxxx (as in lxc launch ubuntu:18.04 c1) are LXD.

In my tutorial, I describe how to set up a profile in LXD that has all the GUI prerequisites.
Then, you can launch your new container specifying that profile, and the container is automatically a GUI container.

If you are going to stick with LXC, then you can try to interpret the commands from LXD to plain LXC.
I am not familiar with LXC and I cannot help you here.
I’ll be happy though to see such a tutorial for LXC, and it would be great if you could do the write-up.

Hi simos,
Thank you for that clarification. I have solved the mystery of the “container not running/container running” anomaly. I started the container under my user name but when I tried to use lxc-config it failed because the command required root privilege. As root I got the message that the container was not running. As user, I could see the container running. Interesting that the container even isolates itself from root on the host OS.

I am flattered that you would suggest I do a write-up on the lxc-xxxxx commands but I’m still quite new to all this and don’t really feel qualified to give directions yet. What little I know is from reading the man pages and fumbling my way through this. Perhaps once I’ve worked through actually getting a gui going in a container I could write up how I did it using the lxc-xxxx commands. I an doing this in little fits and starts just as an exercise in trying to stay current with technology.

Best regards,
Bob G.

how about running lightdm/xorg from LXD like XServer inside LXC container ? do you have a tutorial for it?

1 Like