Pulseaudio in a Docker container on RPI3


Hey Guys! I was just wondering if anyone has ever managed to get pulseaudio running inside of a docker container on the raspberry pi 3? I am trying to follow this tutorial (https://gist.github.com/oleq/24e09112b07464acbda1) to try and create a bluetooth speaker out of the rpi, but pactl fails as follows:

# pactl list sources short
Connection failure: Connection refused
pa_context_connect() failed: Connection refused

Any help would be much appreciated!


I have a feeling that it means that pulseaudio is not actually running at the time you are running pactl. I’m seen this error when pulseaudio is started manually, and then after some idle time it exited. Thus it’s most likely configuration issue?

This particular issue I got fixed by adding exit-idle-time = -1 to /etc/pulse/daemon.conf, so it does not stop after the default 20s idle time. Tested it with something like this:

FROM resin/%%RESIN_MACHINE_NAME%%-debian

WORKDIR /usr/src/app

RUN apt-get update && \
     apt-get install pulseaudio alsa-utils mplayer wget

RUN echo "exit-idle-time = -1" >> /etc/pulse/daemon.conf

RUN wget https://mp3d.jamendo.com/download/track/15655/mp32/ -O test.mp3

CMD pulseaudio --start && while : ; do mplayer -ao pulse test.mp3; done

Two main comments. First, this is horrendous playback, it’s popping and skipping around in the track, it plays, but RPi needs some more adjustments to the daemon.conf to play back properly.

Second, I’m sure the startup would be better with systemd done properly. I’ve seen that ArchLinux uses socket activation by default, that should start things up on demand?

Just some thoughts, this is definitely not the full solution yet, would love to hear your feedback!