How to run GUI applications in an LXC Container

In the post, I’ll show how I got GUI applications to run in a LXC Container.
I have Ubuntu Desktop 16.04 LTS (Xenial release) installed on my machine.

Installation and Setup Steps

 

Install LXC
sudo apt install -y lxc

The system now has all the LXC commands available, all its templates as well as the Python3 binding to script LXC.

See: https://help.ubuntu.com/lts/serverguide/lxc.html#lxc-installation

Create a Container

This creates a privileged container called ethsandbox from the Ubuntu distribution, Xenial release, for amd64 architecture:

sudo lxc-create -n ethsandbox -t ubuntu -- -r xenial

## # The default user is 'ubuntu' with password 'ubuntu'! # Use the 'sudo' command to run tasks as root in the container. ##

List containers:

sudo lxc-ls -f

NAME STATE AUTOSTART GROUPS IPV4 IPV6 ethsandbox STOPPED 0 - - -
Start Container
sudo lxc-start -d -n ethsandbox

Get detailed container information. Take note of the container’s IP address shown below:

sudo lxc-info -n ethsandbox

Name: ethsandbox State: RUNNING PID: 28605 IP: 10.0.3.129 CPU use: 1.01 seconds BlkIO use: 60.66 MiB Memory use: 80.02 MiB KMem use: 5.84 MiB Link: vethQRIHXO TX bytes: 1.59 KiB RX bytes: 12.54 KiB Total bytes: 14.13 KiB
Configure Sandbox

Secure login into the new container. The password for default user ubuntu is ubuntu.
At this point, ssh will fail to forward X because there is no xauth.

ssh -X ubuntu@10.0.3.129

To connect using ssh with X11 forwarding, install the xauth package.
First update the package lists for upgrades with outstanding package updates, as well as with new packages that have just come to the repositories:

sudo apt-get update

Install xauth package:

sudo apt-get install xauth

Exit the container:

exit

..and re-enter:

ssh -X ubuntu@10.0.3.129

Install Firefox – our GUI test application:

sudo apt-get install -y firefox

Run Firefox:

firefox

Leave a Reply

Your email address will not be published. Required fields are marked *