EXSUM: Audio Support in Containers

Not many people seem to know how to support audio in containers. Here is an example for forwarding Pulseaudio into a container.

host_ip="$(ip -4 -o a| grep docker0 | awk '{print $4}' | cut -d/ -f1)"
ss -nlp | grep 34567

docker run -it --privileged --rm \
    --name pulsecontainer \
    --env PULSE_SERVER=tcp:${host_ip}:34567 \
    ubuntu:20.04 bash

This will open a shell into the container. However, before going there run the following on host (e.g. in new shell):

container_ip="$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' pulsecontainer)"
pactl load-module module-native-protocol-tcp  port=34567 auth-ip-acl=${container_ip}

Now play audio in container, e.g. online radio via MPlayer:

apt update && apt install -y mplayer
mplayer -playlist "http://www.ndr.de/resources/metadaten/audio/m3u/ndrloop5.m3u"

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s