I want to play sound on Ubuntu 16.04 on Docker using PulseAudio and ALSA. However it outputs an error
Device or resource busy. I think this is because the default device of ALSA is not set to the PulseAudio sound server (Note: it's set to the PulseAudio on the host Ubuntu). How can I change the default device to it? For example, can I do so by creating
~/.asoundrc or by modifying
Steps to reproduce
$ # On the host Ubuntu... $ aplay -L | head -n9 default Playback/recording through the PulseAudio sound server null Discard all samples (playback) or generate zero samples (capture) pulse PulseAudio Sound Server sysdefault:CARD=PCH HDA Intel PCH, ALC295 Analog Default Audio Device $ aplay /usr/share/sounds/alsa/Front_Center.wav Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono $ paplay /usr/share/sounds/alsa/Front_Center.wav # Success
$ # On the Docker container... $ sudo docker run -it --device /dev/snd ubuntu:16.04 /bin/bash root@81af4bf99890:/# apt update root@81af4bf99890:/# apt install alsa-base alsa-utils pulseaudio root@81af4bf99890:/# aplay -L | head -n10 null Discard all samples (playback) or generate zero samples (capture) pulse PulseAudio Sound Server default:CARD=PCH HDA Intel PCH, ALC295 Analog Default Audio Device sysdefault:CARD=PCH HDA Intel PCH, ALC295 Analog Default Audio Device root@81af4bf99890:/# aplay /usr/share/sounds/alsa/Front_Center.wav ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave aplay: main:722: audio open error: Device or resource busy root@81af4bf99890:/# paplay /usr/share/sounds/alsa/Front_Center.wav Connection failure: Connection refused pa_context_connect() failed: Connection refused
- Host: Ubuntu 17.04
- Docker: 17.09.0-ce
On my environment, Jess's images don't work, too. Here is an example log.
$ # When I play some sounds on host, `jess/spotify` fails to play music. $ sudo docker run -it \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY=unix$DISPLAY \ --device /dev/snd \ --name spotify \ jess/spotify Gtk-Message: Failed to load module "canberra-gtk-module" libGL error: MESA-LOADER: failed to retrieve device information libGL error: Version 4 or later of flush extension not found libGL error: failed to load driver: i915 libGL error: failed to open drm device: No such file or directory libGL error: failed to load driver: i965 [1115/043835.051841:ERROR:sandbox_linux.cc(344)] InitializeSandbox() called with multiple threads in process gpu-process. [1115/043840.945653:ERROR:web_plugin_impl.cc(38)] Widevine registration is not supported after context initialization (spotify:1): GLib-GIO-CRITICAL **: g_dbus_connection_send_message: assertion 'G_IS_DBUS_CONNECTION (connection)' failed ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
The last line says that there is an error related to ALSA. (Note that
jess/spotifycan play music when there is no other software that plays sound. This may be because the sound device is not busy in such a case.)
- Although I self-answered this question, I still want more sophisticated solution or detailed explanation of the reason that some options are needed. Any comments would be appreciated. Thank you.