Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can my docker container app access the host's microphone and speaker? (Mac, Windows, Linux)

Tags:

docker

I'm building a headless softphone application. I know I can build wss or web server with the given tools... but my web app needs to do some pjsip and other codec things with the host's speaker and microphone. Are these devices shared between the mac/windows/linux hosts and the docker container?

like image 481
Richard Avatar asked Aug 15 '17 20:08

Richard


People also ask

Can a Docker container access host?

To access host machine from the docker container you must attach an IP alias to your network interface. You can bind whichever IP you want, just make sure you're not using it to anything else. Then make sure that you server is listening to the IP mentioned above or 0.0.

Can a Docker container run on both Windows and Linux?

You can run both Linux and Windows programs and executables in Docker containers. The Docker platform runs natively on Linux (on x86-64, ARM and many other CPU architectures) and on Windows (x86-64). Docker Inc. builds products that let you build and run containers on Linux, Windows and macOS.

Can Docker containers talk to each other by default?

For containers to communicate with other, they need to be part of the same “network”. Docker creates a virtual network called bridge by default, and connects your containers to it. In the network, containers are assigned an IP address, which they can use to address each other.

Can Docker desktop run Windows and Linux containers side by side?

With Docker for Windows started and Windows containers selected, you can now run either Windows or Linux Containers simultaneously.


2 Answers

I had to use the microphone and speakers of the linux host from a docker container. Since in linux/unix based OSs devices are special files in the file system this solution should apply. In Windows it won't.

I discovered that the ubuntu image I was using in my container didn't have the ALSA drivers needed to use the soundcard. So after installing them in the docker container:

sudo apt-get install -y alsa-base alsa-utils

and running the docker image with the following parameters:

docker run --device /dev/snd:/dev/snd <container_name>

it worked. You can test if it works by invoking aplay and arecord inside the container.

like image 123
atavio Avatar answered Sep 17 '22 10:09

atavio


Never tried with speakers and microphone, anyway you can access host devices using the option --device in docker run.

See Add host device to container (–device) in Docker run reference for more details.

like image 45
gile Avatar answered Sep 21 '22 10:09

gile