How to play sound in a docker container

I am trying to connect a text-to-speech application for sharing code with other developers, however the problem that I am currently facing is that the docker container cannot find a sound card on my main machine.

When I try to play a wav file in a docker container

root@3e9ef1e869ea :/# aplay Alesis-Fusion-Acoustic-Bass-C2.wav ALSA lib confmisc.c:768:(parse_card) cannot find card '0' ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directory ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default aplay: main:722: audio open error: No such file or directory 

I assume that the main problem is that the docker container cannot receive a sound card on my host.

I still have

  • I installed alsa-utils and most alsa dependencies in my docker container.
  • Added --group-add audio when starting the container by specifying docker run --group-add audio -t -i self/debian /bin/bash

I'm not sure if this is possible even with a docker (I'm not quite sure how hardware resources, such as sound cards, are shared between containers). I am using a debian container on a Mac OS Yosemite host.

+7
docker audio alsa
source share
1 answer

Maybe you need to install / dev / snd, see how Jess Fraselle launches the Spotify container, from

https://blog.jessfraz.com/post/docker-containers-on-the-desktop/

you will notice

docker run -it \ -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket -e DISPLAY=unix$DISPLAY \ # pass the display --device /dev/snd \ # sound --name spotify \ jess/spotify

or for Chrome, at the end

docker run -it \ --net host \ # may as well YOLO --cpuset-cpus 0 \ # control the cpu --memory 512mb \ # max memory it can use -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket -e DISPLAY=unix$DISPLAY \ # pass the display -v $HOME/Downloads:/root/Downloads \ # optional, but nice -v $HOME/.config/google-chrome/:/data \ # if you want to save state --device /dev/snd \ # so we have sound --name chrome \ jess/chrome

+8
source share

All Articles