tmn103
tmn103

Reputation: 339

How to get Docker audio and input with Windows or mac host?

I'm trying to create a Docker image that works with a speaker and microphone.

I've got it working with Ubuntu as host using:

docker run -it --device /dev/snd:/dev/snd <docker_container>

I'd also like to be able to use the Docker image on windows and mac hosts, but can't find the equivalent of /dev/snd to make use of the host's speaker/microphone.

Any help appreciated

Upvotes: 4

Views: 6256

Answers (1)

Wm. Pollock
Wm. Pollock

Reputation: 41

I was able to get playback on Windows using pulseaudio.exe.

1] Download pulseaudio for windows: https://www.freedesktop.org/wiki/Software/PulseAudio/Ports/Windows/Support/

2] Uncompress and change the config files.

2a] Add the following line to your $INSTALL_DIR/etc/pulse/default.pa:

load-module module-native-protocol-tcp listen=0.0.0.0 auth-anonymous=1 

This is an insecure setting: there are IP-based ones that are more secure but there's some Docker sorcery involved in leveraging them I think. While the process is running anyone on your network will be able to push sound to this port; this risk will be acceptable for most users.

2b] Change $INSTALL_DIR/etc/pulse//etc/pulse/daemon.conf line to read: exit-idle-time = -1

This will keep the daemon open after the last client disconnects.

3) Run pulseaudio.exe. You can run it as

start "" /B "pulseaudio.exe"

to background it but its tricker to kill than just a simple execution.

4) In the container's shell:

export PULSE_SERVER=tcp:127.0.0.1

One of the articles I sourced this from (https://token2shell.com/howto/x410/enabling-sound-in-wsl-ubuntu-let-it-sing/) suggests recording may be blocked in Windows 10.

Upvotes: 4

Related Questions