title: How to access mac os x microphone inside docker container?
body: <p>I am running a docker container with the python code that records the sound for few seconds using the host MacBook Pro build in microphone. </p>
  
  <p>Part of my challenge is to determine how to provide access/share Macbook Pro microphone inside the Docker container. Most of the existing questions on stack overflow or elsewhere provide solutions for Linux based distros but I don't have much luck to do the same with mac os. </p>
  
  <p>The OS version details: </p>
  
  <pre><code>System Version: macOS 10.14.2 (18C54)
  Kernel Version: Darwin 18.2.0
  </code></pre>
  
  <p>Docker:</p>
  
  <pre><code>Client: Docker Engine - Community
   Version:           18.09.2
   API version:       1.39
   Go version:        go1.10.8
   Git commit:        6247962
   Built:             Sun Feb 10 04:12:39 2019
   OS/Arch:           darwin/amd64
   Experimental:      false
  
  Server: Docker Engine - Community
   Engine:
    Version:          18.09.2
    API version:      1.39 (minimum version 1.12)
    Go version:       go1.10.6
    Git commit:       6247962
    Built:            Sun Feb 10 04:13:06 2019
    OS/Arch:          linux/amd64
    Experimental:     false
  </code></pre>
  
  <p>The python code is simple and working as expected on the host. </p>
  
  <pre><code>import sounddevice as sd
  import numpy as np
  fs = 48000
  duration=5
  rec = sd.rec(int(duration * fs), samplerate=fs, channels=1, blocking=True)
  print(rec)
  </code></pre>
  
  <p>Here is the docker file:</p>
  
  <pre><code>FROM python:3
  
  RUN apt-get -y update
  RUN apt-get -y install libasound-dev
  RUN apt-get -y install portaudio19-dev
  
  WORKDIR /usr/src/app
  COPY requirements.txt ./
  COPY AudioRecordingTest.py ./
  RUN pip install -r requirements.txt
  CMD [ "python", "./AudioRecordingTest.py" ]
  </code></pre>
  
  <pre><code>docker build -t audiorecording:1.0 .
  
  docker run -it --rm --device --privileged=true DONT_KNOW_ABOUT_THIS_PART:/dev/snd  audiorecording:1.0 
  </code></pre>
  
  <p>Ideally should able to mount/share the microphone as you do when Linux is the host. If not what are the other possible solutions? </p>
  
  <pre><code>docker run -it --rm --device --privileged=true DONT_KNOW_ABOUT_THIS_PART:/dev/snd  audiorecording:1.0 
  </code></pre>