[lxc-users] how to use pulseaudio to get audio/sound from an LXC container

brian mullan bmullan.mail at gmail.com
Fri Jan 15 17:14:32 UTC 2016


Last week I'd posted to the alias 1 method I'd done to get a working
Desktop in an LXC container with sound/clipboard/printing.    That post was
just part of figuring out out how to get sound working from a container
desktop and isn't necessarily the best 'remote desktop' solution nor the
only one (x2go is great & guacamole also works).

Anyway audio/sound has always been a problem for me with LXC containers.

I found that Pulseaudio's TCP module can make it simple & easy to support
audio/sound from a container.

The container has to have pulseaudio installed.
Your Container User acct also will need to have the following Environment
variable set for you at login:

*PULSE_SERVER=10.0.3.1*

That will tell the container pulseaudio to redirect any audio/sound to the
Host (which in the container is at 10.0.3.1).   You can just put that in
your .bashrc file in the Container.

The above IP could also be the IP address of an actual remote machine if
you were doing some kind of remote desktop to a linux machine's and/or its
containers.

In the container you also will want to make sure your UserID is a member of
the
following "groups":


*pulse*

*pulse-access*
*audio*

In the Host, the setup is also very simple.

All you need to do is add the following 2 lines to the Host's Pulseaudio
configuration file located at - /etc/pulse/system.pa.

Once that's done either kill the Pulseaudio daemon (it automatically
restarts to pick up the 2 lines) or wait till your next reboot.


*load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;10.0.3.0/24
<http://10.0.3.0/24>load-module module-zeroconf-publish*

reference the Pulseaudio section on Authorization:
http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Network/

The 1st line above tells Pulseaudio in the Host to load its TCP module at
startup (its not by default) and also to apply that access list (ACL) which
says to accept sound connections ONLY from the localhost and also from any
host on the 10.0.3.x network.

You can be as restrictive with the ACL as you want but this will let any
container play sound on the host.

That's it... sound will work from the container.

A couple extra tips for container Desktop users are these:

With the "load-module" the  ACL can accept pulseaudio connections from
anywhere given the right ACL and that PulseAudio's Port 4713 is open in the
network.   So you could have 2 containers, one playing sound to your Host
and another redirecting sound to a laptop on your deck?

If you have a Desktop environment installed in the container you might also
want to install 2 pulseaudio mgmt tools:

pavucontrol
paprefs

If you want to use Firefox in the Container Desktop environment I did find
& report what I considered a bug.

Executing firefox from a terminal in the container (with the above
configuration) sound would work & play on the Host's speakers.

Executing firefox from a menu in the Container's Desktop did not.   I found
that executing Firefox from the menu didn't directly execute the firefox
binary but a script (/user/lib/firefox/firefox.sh) which I guess did not
inherit the User's environment & thus the PULSE_SERVER setting.

If you add *PULSE_SERVER=10.0.3.1 *to the top of that firefox.sh script
that will fix it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20160115/01bdde0d/attachment.html>


More information about the lxc-users mailing list