Code Monkey home page Code Monkey logo

docker-pulseaudio-example's Introduction

Docker PulseAudio Example

An example of a PulseAudio app working within a Docker container using the hosts sound system

Docker Hub

Building

./buid.sh

Running

./host_runner.sh

Explanation

Getting a PulseAudio app to work within a Docker container is harder than it looks. This example is designed to produce the smallest working configuration that can be used in your own containers.

To be clear this is designed so the app within the Docker container does not run a PulseAudio server. Instead the app connects as a client directly to the hosts PulseAudio server and uses it's configuration/devices to output the sound. This is achieved by mapping the UNIX socket used by PulseAudio in the host into the container and configuring its use.

Most of the complexity of the Dockerfile is setting up a non root user. This is kept in the example as near all uses of this should not be running the app as root.

Common / Known Issues

SHM

shm_open() failed: No such file or directory Is caused by PulseAudio trying to use Shared Memory (/dev/shm or /run/shm) as a performance enhancement. In this example SHM is disabled to prevent this issue.

TCP / Avahi

This would be another method to configure PulseAudio by enabling the host server to open an TCP server and the container connecting to it. This was avoided as it:

  • Unnecessarily causes the container to be networked to the host.
  • Requires additional PulseAudio modules and changed configuration on the host.
  • Is less performant.

docker-pulseaudio-example's People

Contributors

thebiggerguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

docker-pulseaudio-example's Issues

Getting "connection refused" for pa clients

With a new Pulseaudio server (I'm currently running 13.99, but I understand this applies for version 12 and above), having the cookie is no longer sufficient to allow the Pulseaudio clients to connect.

I've worked around the problem with the same technique as described in the x11docker issue #71 - creating an anonymous one-use pulseaudio socket and mounting it instead of the primary socket.

My run script looks something like this:

DOCKERID=${RANDOM} # or some other value that makes sense, for example - a counter
pasocket=$(pactl load-module module-native-protocol-unix socket=$HOME/.config/pulse/docker-socket$DOCKERID auth-anonymous=1)
docker run ... -v $HOME/.config/pulse/zoiper-socket$DOCKERID:/home/user/.pulse.socket ...
# after run
pactl unload-module $pasocket
rm -f $HOME/.config/pulse/zoiper-socket$DOCKERID

[ user is the user name of the unprivileged user inside docker]

The /etc/pulse/client.conf has to be updated, but that is not enough for command line utilities such as pacat - these need to also have the PULSE_SERVER environment variable set to unix:/home/user/.pulse.socket. I solved this by tacking an export at the end of /home/user/.bashrc. I check that this works well for the GUI applications I'm running in the docker.

pa_context_connect() failed when X11 socket and DISPLAY variable are passed in docker run

Hello,
Firstly thanks for publishing this it's really useful. I've been using it as a starting point trying to get pulseaudio in docker working on some other applications. One weird thing I've discovered is that passing the X11 socket and DISPLAY variable to docker causes a "pa_context_connect() failed: Connection refused", as the applications I'm working on are GUI apps I clearly need to be able to pass this info.

For example, if I do:

docker run -it --rm -v /run/user/1000/pulse:/run/user/1000/pulse thebiggerguy/docker-pulseaudio-example

I see

Opening a playback stream with sample specification 's16le 2ch 44100Hz' and channel map 'front-left,front-right'.
Connection established.
Stream successfully created.
Buffer metrics: maxlength=4194304, tlength=352800, prebuf=349276, minreq=3528
Using sample spec 's16le 2ch 44100Hz', channel map 'front-left,front-right'.
Connected to device alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1 (index: 1, suspended: no).
Stream started.

And hear lovely loud noise from /dev/urandom on my host

However if I do:

docker run -it --rm -e DISPLAY=unix$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v /run/user/1000/pulse:/run/user/1000/pulse thebiggerguy/docker-pulseaudio-example

That is to say I include the option -e DISPLAY=unix$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix in the docker run I see:

Opening a playback stream with sample specification 's16le 2ch 44100Hz' and channel map 'front-left,front-right'.
Connection failure: Connection refused
pa_context_connect() failed: Connection refused

I don't suppose that you could point me at what I might be missing? Google searches seem to be a bit light when it comes to the subject of pulseaudio from docker, which is what led me here in the first place.

Many thanks in advance.

Getting an access denied

I tried running the minimal sample with either root or not (not that as non-root from within the container the user cannot access the pulse socket):

$ docker run -it --user root --volume=/run/user/$(id -u)/pulse:/run/user/1000/pulse thebiggerguy/docker-pulseaudio-example
Opening a playback stream with sample specification 's16le 2ch 44100Hz' and channel map 'front-left,front-right'.
Connection failure: Access denied

Else this would allow to simplify https://github.com/wernight/docker-mopidy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.