Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play sound in a Docker container on Mac OS Yosemite

Tags:

docker

audio

alsa

I'm trying to dockerize a text to speech application for sharing the code with other developers, however the issue I am having right now is the docker container cannot find the sound card on my host machine.

When I try to play a wav file in my 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 guess that the main problem is docker container is unable reach the sound card on my host.

So far I have

  1. I installed alsa-utils and most of the alsa dependencies within my docker container.
  2. Added --group-add audio while running the container by specifying docker run --group-add audio -t -i self/debian /bin/bash

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

like image 921
Anoop Avatar asked Dec 11 '16 05:12

Anoop


People also ask

Can I run a Docker container on Mac?

Docker Desktop currently supports macOS Catalina, macOS Big Sur, and macOS Monterey. At least 4 GB of RAM. VirtualBox prior to version 4.3. 30 must not be installed as it is not compatible with Docker Desktop.

How do I run Docker natively on a Mac?

Currently, to use Docker on Mac and Windows requires the use of Docker Toolbox. You have to download it, install a bunch of tools and dependencies for it to work. And since Docker uses Linux-specific tools you can't run it natively. Instead, you have to use docker-machine and attach to a VirtualBox VM on your system.

Where are Docker volumes macOS?

As a Linux user, you learn that Volumes are stored in a part of the host filesystem managed by Docker, and that is /var/lib/docker/volumes . When you're running Docker on a Windows or Mac OS machine, you will read the same documentation and instructions but feel frustrated as that path don't exist on your system.


1 Answers

It is definitely possible, you need to mount /dev/snd, see how Jess Frazelle launches a 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 
like image 163
user2915097 Avatar answered Sep 21 '22 18:09

user2915097