Documenting Problems That Were Difficult To Find The Answer To

How Do I Get X11 Applications Running in a LXC Container?

This demonstration assumes Ubuntu 14.04.3 Trusty Tahr running LXC.

Firstly you will want to build your LXC container.

$ sudo lxc-create lxc-create -n my-x-container -t ubuntu -- -r trusty
$ sudo lxc-start -d -n my-x-container
$ sudo lxc-ls -f
NAME            STATE    IPV4        IPV6  AUTOSTART  
my-x-container  RUNNING  -     NO         
$ ssh -X ubuntu@ # will fail to forward X because no xauth

Before you can connect using ssh with X11 forwarding you will need the xauth package installed, run the following command from within the container after attaching to the container’s console:

$ sudo lxc-console -n my-x-container
# sudo apt-get install xauth

Note that you will need to press ctrl-A, Q to exit the console.

This is enough if you merely want to run xclock:

# sudo apt-get install x11-apps
$ ssh -X ubuntu@
# /usr/bin/xclock

But you will also need dbus and dbus-x11 if you want to run Firefox:

# sudo apt-get install dbus dbus-x11
# sudo apt-get install firefox

Now you can run Firefox:

$ ssh -X ubuntu@
# /usr/bin/firefox

How About Sound Over SSH/X11?

First, as your ordinary user (not root) on your desktop run the X application paprefs (from the paprefs package).

Navigate to the “Network Server” tab and select the “Enable network access to local sound devices” checkbox. Then close the window.

Enable network access to local sound devices

Enable network access to local sound devices

To confirm this is working from your desktop type xprop -root PULSE_SERVER and you should see tcp:localhost:4713 listed, e.g.:

$ xprop -root PULSE_SERVER
PULSE_SERVER(STRING) = "{0e1ca025b25b2cccd20066e2c5f303c0}unix:/run/user/1000/pulse/native tcp:localhost:4713 tcp6:localhost:4713"

Next you will need to install the pulseaudio package in your container.

# sudo apt-get install pulseaudio

And then every connection you make you will have to define the PULSE_SERVER environment variable to tell X11 applications where to connect to in order to send audio.

The SSH connection you make will not only have to do X forwarding (-X) but also connect locally to port 4713 whenever a connection is made to port 14713 within your container/SSH session (-R 14713:localhost:4713).

$ ssh -X ubuntu@ -R 14713:localhost:4713
# export PULSE_SERVER="tcp:localhost:14713"
# /usr/bin/firefox # now can watch YouTube videos with sound from container

2 responses to “How Do I Get X11 Applications Running in a LXC Container?

  1. leomaheo May 18, 2016 at 2:04 am

    Do I run “sudo apt-get install xauth” in the container or on the host? In the container I would think, right?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: