pulseaudio and docker

How do I configure pulseaudio to work with containers?
I was able to run firefox and vlc in a container on kubuntu 15.10 without an issue, but I haven’t been able to get it to work in tumbleweed.

I’ve tried creating the image with alpine, opensuse (with packman), and most recently went back to ubuntu


FROM ubuntu:16.04

RUN echo 'deb http://archive.ubuntu.com/ubuntu/ xenial multiverse' >> /etc/apt/sources.list && \
    echo 'deb-src http://archive.ubuntu.com/ubuntu/ xenial multiverse' >> /etc/apt/sources.list

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
       vlc \
       vlc-plugin-* \
    && rm -rf /var/lib/apt/lists/*

RUN groupadd -g 1000 user \                                                                  
    && useradd --create-home -d /home/user -g user -u 1000 user \
    && usermod -a -G audio,video user
                                                                                             
USER user                                                                                    
WORKDIR /home/user

ENTRYPOINT "vlc"]


I’m running the image with the following command


docker run -d \
  -v /etc/localtime:/etc/localtime:ro \
  --device /dev/snd \
  --device /dev/dri \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  -e DISPLAY=unix$DISPLAY \
  --name vlc \
  rdesfo/vlc

I’m getting the following error


vlc
[0000000000e0c238] pulse audio output error: PulseAudio server connection failure: Connection refused
[0000000000e13768] dbus interface error: Failed to connect to the D-Bus session daemon: /usr/bin/dbus-launch terminated abnormally without any error message
[0000000000e13768] core interface error: no suitable interface module
[0000000000d39178] core libvlc error: interface "dbus,none" initialization failed
[0000000000d39178] core libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
libGL error: failed to open drm device: Permission denied
libGL error: failed to load driver: i965
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4292:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4292:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4292:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4771:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM default
[0000000000e0c238] alsa audio output error: cannot open ALSA device "default": No such file or directory
[0000000000e0c238] core audio output error: module not functional
[00007fd7b402e9c8] core decoder error: failed to create audio output
[00007fd798001ed8] dbus_screensaver inhibit error: cannot connect to session bus: /usr/bin/dbus-launch terminated abnormally without any error message
[00007fd798001268] xcb vout display error: shared memory server-side error: X11 error 10
[00007fd798001268] xcb vout display error: same error on retry: X11 error 10
[00007fd798001268] xcb_xv vout display: using buggy X11 server - SSH proxying?
[00007fd798001268] xcb vout display error: shared memory server-side error: X11 error 10
[00007fd798001268] xcb vout display error: same error on retry: X11 error 10
[00007fd798001268] xcb_xv vout display: using buggy X11 server - SSH proxying?
[00007fd798001268] xcb vout display error: shared memory server-side error: X11 error 10
[00007fd798001268] xcb vout display error: same error on retry: X11 error 10
[00007fd798001268] xcb_xv vout display: using buggy X11 server - SSH proxying?
QObject::~QObject: Timers cannot be stopped from another thread

Looks like you posted your Ubuntu Dockerfile, not the Dockerfile creating an openSUSE container… Or, is that what you are actually doing, running an Ubuntu container on openSUSE?

Assuming you’re running the Ubuntu container in an openSUSE TW,

  • Did you first verify that Pulseaudio is working in your HostOS (TW)?
  • Is there a specific guide you’re following that describes the Pulseaudio architecture in openSUSE?
    (Personally, I haven’t kept up with Pulseaudio continuously since so much seemed to be change continuously through 13.2, and I don’t know if there are substantial differences in TW)
  • Did you try inserting your command line options one at a time into your Dockerfile?
  • Are you launching your Container using root permissions or a normal User? Remember that invoking with less than root permissions might be configurable, accessing system subsystems like Pulseaudio likely isn’t one of them.

TSU

Looks like you posted your Ubuntu Dockerfile, not the Dockerfile creating an openSUSE container… Or, is that what you are actually doing, running an Ubuntu container on openSUSE?

 [size=4]I'm  running ubuntu image (container) because I had it working when running  on a ubuntu host and I don't want to deal with the pacman repo.

[/size]

Assuming you’re running the Ubuntu container in an openSUSE TW,

  • Did you first verify that Pulseaudio is working in your HostOS (TW)?
  • Is there a specific guide you’re following that describes the Pulseaudio architecture in openSUSE?
    (Personally, I haven’t kept up with Pulseaudio continuously since so much seemed to be change continuously through 13.2, and I don’t know if there are substantial differences in TW)
 No, I was hoping there would be an opensuse pulseaudio guru on the forum that could point me in the write direction 
  • Did you try inserting your command line options one at a time into your Dockerfile?
  I configured the dockerfile by running 
sudo docker run --rm it ubuntu:16.04 bash

and going through each command. So the environment is correct.

  • Are you launching your Container using root permissions or a normal User? Remember that invoking with less than root permissions might be configurable, accessing system subsystems like Pulseaudio likely isn’t one of them.
  I created a user in the container's image <1st file> and vlc is run by "user" in the container (vlc gives an error when run as root).  Docker itself has to be run with someone who has root access, run command in <2nd file>.  Since docker 1.2 the `--device /dev/snd` should be able to be used to add sound access to a container.
  • Did you first verify that Pulseaudio is working in your HostOS (TW)?

If sound (or for that matter any other device) is not working on your HostOS, I doubt it’d be working in a container.

TSU

no, sound is working on host and not working in the containerized vlc (and also firefox).