Skip to content

Instantly share code, notes, and snippets.

@janvda
Last active December 5, 2020 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janvda/e877ee01686697ceaaabae0f3f87da9c to your computer and use it in GitHub Desktop.
Save janvda/e877ee01686697ceaaabae0f3f87da9c to your computer and use it in GitHub Desktop.
Using pulseaudio in docker container

Host Setup

  1. Pulseaudio must be installed on the host and the pulseaudio server must be running on the host machine.

This can be checked through following command:

[root@nuc-jan ~]# ps -ef | grep pulseaudio
pulse      16123   16090  0 20:09 ?        00:00:00 /usr/bin/pulseaudio --daemonize=no
root       16475   16125  0 20:09 pts/0    00:00:00 grep --color=auto pulseaudio
[root@nuc-jan ~]# 
  1. Pulseaudio must be run system-wide mode

For this the following line must be set in /etc/pulse/daemon.conf

system-instance = yes
  1. The pulse user needs to be in the audio and bluetooth groups in order to be able to use ALSA and bluetooth devices.
# adding user pulse to audio group
usermod -a -G audio pulse
  1. Specify location of unix pulseaudio socket and allow anonymous client access by updating following section in /etc/pulse/system.pa

from :

### Load several protocols
.ifexists module-esound-protocol-unix.so
load-module module-esound-protocol-unix
.endif
load-module module-native-protocol-unix

into :

### Load several protocols
.ifexists module-esound-protocol-unix.so
load-module module-esound-protocol-unix
.endif
load-module module-native-protocol-unix  auth-anonymous=true socket=/tmp/pulseaudio.socket
  1. Set pulseaudio unix socket for the pulse audio client and disable autospawn in /etc/pulse/client.conf as follows

The same socket location must be specified as set in point 3.

default-server = unix:/tmp/pulseaudio.socket
autospawn = no 

Test Pulseaudio on the host

  1. Assure that the pulseaudio-utils are installed.
  2. request the pulseaudio info
[root@nuc-jan pulse]# pactl info
Server String: unix:/tmp/pulseaudio.socket
Library Protocol Version: 32
Server Protocol Version: 32
Is Local: yes
Client Index: 0
Tile Size: 65472
User Name: pulse
Host Name: nuc-jan.borsbeek
Server Name: pulseaudio
Server Version: 11.1-rebootstrapped
Default Sample Specification: s16le 2ch 44100Hz
Default Channel Map: front-left,front-right
Default Sink: auto_null
Default Source: auto_null.monitor
Cookie: 1a6b:a182
[root@nuc-jan pulse]# 
  1. Request the pulseaudio modules,sinks, sources, clients.
[root@nuc-jan pulse]# pactl list
Module #0
        Name: module-udev-detect
        Argument: 
...
  1. test speaker - for this assure alsa-utils is intalled.
# test pulseaudio play
paplay /usr/share/sounds/alsa/Front_Center.wav 

# test alsa play (you can do this if previous command doesn't work).
aplay /usr/share/sounds/alsa/Front_Center.wav 

Troubleshooting pulseaudio on the host

  1. You can increase log level in /etc/pulse/daemon.conf. E.g. add following line:
log-level = debug
  1. Following command can then be used to see what is logged:
journalctl | grep pulseaudio
  1. Check if sound device is used:
lsof /dev/snd/*

fuser -v /dev/snd/*
  1. list cards using alsa
aplay -L
  1. list sinks/sources using pulseaudio
pactl list sinks
pactl list sources
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment