I know it's possible by using pulse audio on a Linux host system But paprefs
is built for linux not mac.

- 2,167
- 3
- 22
- 33
2 Answers
Install PulseAudio on the Mac:
brew install pulseaudio
Run the daemon:
pulseaudio --load=module-native-protocol-tcp --exit-idle-time=-1 --daemon
In your Docker container:
- Install PulseAudio, e.g.,
apt-get install pulseaudio
. - set the following environment variable:
ENV PULSE_SERVER=docker.for.mac.localhost
When you run it, share your ~/.config/pulse
directory with the container for authentication.
You can run a test to see if it's working like this:
docker run -it -e PULSE_SERVER=docker.for.mac.localhost -v ~/.config/pulse:/home/pulseaudio/.config/pulse --entrypoint speaker-test --rm jess/pulseaudio -c 2 -l 1 -t wav

- 5,573
- 3
- 36
- 42
-
Turns out I had stereo -> mono set in OS X accesibility settings. Stereo works fine. Thanks! – John C. May 18 '20 at 23:02
-
3In a recent release of Docker for Mac (and Windows) they changed the magic hostname to `host.docker.internal` and I'd recommend changing the `-v` old syntax to the newer `--mount type=bind,source=~/.config/pulse,target=/home/pulseaudio/.config/pulse` to avoid creating a config on your host owned as `root` if you hadn't yet run the `brew install pulseaudio` and configured it and give you a nice error about it not existing instead of doing a bad thing, but otherwise this looks awesome. – dragon788 Jul 02 '20 at 22:30
-
Thanks for this. It took me a while to figure out the reason why the test was working but my own container wasn't: the mount ("-v ~/.config/pulse:/home/pulseaudio/.config/pulse") is pointed at the home directory for the "pulseaudio" user, which the jess/pulseaudio image creates. I had to change the mount to point to the home directory of my user. – David Nelson Aug 09 '20 at 05:35
-
1@dragon788 trying to use your suggestion for mounting throws error (says it needs absolute paths). I managed to have it working by weirdly the speaker-test does not produce any output – fllprbt Mar 20 '21 at 18:42
The Docker-for-Mac VM doesn't have any sound passthrough device, so there isn't anything that you could take advantage of from that angle. By contrast, a virtualbox or vmware fusion VM does have the ability to do passthrough audio.
I was able to get pulseaudio installed and working on OSX with the following command:
brew install pulseaudio
I was able to verify this worked by running the following, hearing sound come out of my speakers:
paplay cockatiel.wav
My next step is to find an image that has a copy of paplay
. I found jess/pulseaudio, which appears to be intended to be a pulseaudio server, but I should be able to use it as a client as well.
I found the following guide on the Archlinux Wiki discussing setting up pulseaudio network sound: https://wiki.archlinux.org/index.php/PulseAudio/Examples#PulseAudio_over_network
I was able to adapt it to this situation by doing the following. I edited /usr/local/Cellar/pulseaudio/9.0/etc/pulse/default.pa
on my mac, and uncommented the following two lines:
load-module module-esound-protocol-tcp
load-module module-native-protocol-tcp
I reran paplay cockatiel.wav
on my mac to make sure my changes still worked. the pulseaudio daemon seems to start on demand, and passes its complaints back to paplay
to be printed on my screen if I made a typo. I still have sound with those changes to default.pa, so I'm satisfied that my changes didn't break anything.
Next, I ran the pulseaudio client in a container like this:
docker run --rm -v $HOME:$HOME -w $HOME -it \
-e PULSE_SERVER=192.168.10.23 \
-e HOME=$HOME --entrypoint paplay \
jess/pulseaudio $HOME/cockatiel.wav
What this does is run a container with my local home directory as a volume. This serves two purposes. The first is the fact that my cockatiel.wav is located inside $HOME
. The second is because both the client and the server need to have a copy of the same ~/.config/pulse/cookie
file (per that archlinux wiki guide).
The PULSE_SERVER
environment variable is the en0 IP address of my OSX host, so paplay knows what to connect to.
The HOME
environment variable is necessary so paplay can find the same ~/.config/pulse/cookie
file.
I was able to play sound from a container running on my docker-for-mac via pulseaudio.
As long as you get the ~/.config/pulse/cookie
file to appear in the correct location, you should be able to play sound. You don't have to use a host volume to accomplish this-- you could also do a 'docker cp', or even COPY
it into an image.

- 6,262
- 25
- 40
-
3I get the following error when running paplay piano2.wav $ paplay piano2.wav W: [] caps.c: Normally all extra capabilities would be dropped now, but that's impossible because PulseAudio was built without capabilities support. Connection failure: Connection refused pa_context_connect() failed: Connection refused – valentin_nasta Dec 22 '16 at 23:21
-
@valentin_nasta did you manage to fix the issue with installing PulseAudio on Mac? – Paul Sturgess Jan 29 '17 at 15:44
-
2With current PulseAudio 10.0, running "pulseaudio --daemonize=false -v" doesn't seem to start, get "W: [] socket-util.c: IP_TOS failed: Invalid argument" after adding the two module-esound-protocol-tcp / module-native-protocol-tcp lines. – jamshid Jun 20 '17 at 00:50