To play audio in docker container, you will need to map the audio device of the host to the container
docker run -ti --rm \ -v /dev/snd:/dev/snd \ --privileged \ myContainer sh -c "echo run something"`
For MacOS, PulseAudio needs to be installed
Reference
- Install Pulse Audio
brew install pulseaudio
- Run the daemon (starting using brew services has some issues so use the start command manually)
pulseaudio --load=module-native-protocol-tcp --exit-idle-time=-1 --daemon
To run as service, additional steps are required
- Edit the config file located in
/usr/local/Cellar/pulseaudio/14.2/homebrew.mxcl.pulseaudio.plist
- Add in the additional argument for
--load=module-native-protocol-tcp
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>KeepAlive</key> <true/> <key>Label</key> <string>homebrew.mxcl.pulseaudio</string> <key>ProgramArguments</key> <array> <string>/usr/local/opt/pulseaudio/bin/pulseaudio</string> <string>--load=module-native-protocol-tcp</string> <string>--exit-idle-time=-1</string> <string>--verbose</string> </array> <key>RunAtLoad</key> <true/> <key>StandardErrorPath</key> <string>/usr/local/var/log/pulseaudio.log</string> <key>StandardOutPath</key> <string>/usr/local/var/log/pulseaudio.log</string> </dict> </plist>
- Start the service
brew services start pulseaudio