Running a Docker Soundbox on Mac

These days I experimented with the tiptoi pen from Ravensburger on OSX.

It’s the play command to test the generated content interactively that wants to play sounds. In the Docker setup, the sound is played inside a Docker container without real sound hardware access.

Looking at StackOverflow PulseAudio seems to be an option.

Install PulseAudio on the Mac host

$ brew install pulseaudio
…
To have launchd start pulseaudio now and restart at login:
  brew services start pulseaudio

Either you follow the instructions from brew:

$ brew services start pulseaudio
==> Tapping homebrew/services
…
Tapped 1 command (44 files, 58.7KB).
==> Successfully started `pulseaudio` (label: homebrew.mxcl.pulseaudio)

Or you run the daemon on your own:

$ pulseaudio --load=module-native-protocol-tcp --exit-idle-time=-1 --daemon

Either way, you should check that the daemon is running on the host:

pulseaudio --check -v
W: [] caps.c: Normally all extra capabilities would be dropped now, but that's impossible because PulseAudio was built without capabilities support.
I: [] main.c: Daemon running as PID 11506

Play sounds inside a Docker container

An easy way to debug issues was to use the prepared jess/pulseaudio container:

$ 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

Our use case was to enhance another container - our tttool.

Since our base image supports apt-get it was an easy task to adopt the necessary steps from the image mentioned above:

FROM haskell:8.4.3RUN apt-get update && apt-get install -y \
    espeak \
    vorbis-tools \
    sox \
    alsa-utils \
    libasound2 \
    libasound2-plugins \
    pulseaudio \
    pulseaudio-utils \
    --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

ENV HOME /home/tttool
RUN useradd --create-home --home-dir $HOME tttool \
    && usermod -aG audio,pulse,pulse-access tttool \
    && chown -R tttool:tttool $HOME

…

This way we were able to play the tiptoi product in simulation mode and use the Mac to render the sounds instead of the real tiptoi pen.

Play it safe or play it cool, it’s up to you!

Show Comments