[英]How to expose audio from Docker container to a Mac?
我知道在Linux主机系统上使用脉冲音频是可能的但是paprefs
是为linux而不是mac构建的。
The Docker-for-Mac VM doesn't have any sound passthrough device, so there isn't anything that you could take advantage of from that angle. Docker-for-Mac VM没有任何声音直通设备,因此没有任何东西可以从这个角度利用。 By contrast, a virtualbox or vmware fusion VM does have the ability to do passthrough audio.
相比之下,虚拟机或vmware融合虚拟机确实具有直通音频的功能。
I was able to get pulseaudio installed and working on OSX with the following command: 我能够使用以下命令安装pulseaudio并在OSX上工作:
brew install pulseaudio
I was able to verify this worked by running the following, hearing sound come out of my speakers: 我能够通过运行以下内容验证这是否有效,听到声音来自我的扬声器:
paplay cockatiel.wav
My next step is to find an image that has a copy of paplay
. 我的下一步是找到一个包含
paplay
副本的paplay
。 I found jess/pulseaudio , which appears to be intended to be a pulseaudio server , but I should be able to use it as a client as well. 我找到了jess / pulseaudio ,它似乎是一个pulseaudio 服务器 ,但我也应该能够将它用作客户端 。
I found the following guide on the Archlinux Wiki discussing setting up pulseaudio network sound: https://wiki.archlinux.org/index.php/PulseAudio/Examples#PulseAudio_over_network 我在Archlinux Wiki上找到了以下关于设置pulseaudio网络声音的指南: https : //wiki.archlinux.org/index.php/PulseAudio/Examples#PulseAudio_over_network
I was able to adapt it to this situation by doing the following. 通过执行以下操作,我能够适应这种情况。 I edited
/usr/local/Cellar/pulseaudio/9.0/etc/pulse/default.pa
on my mac, and uncommented the following two lines: 我在我的Mac上编辑了
/usr/local/Cellar/pulseaudio/9.0/etc/pulse/default.pa
,并取消注释以下两行:
load-module module-esound-protocol-tcp
load-module module-native-protocol-tcp
I reran paplay cockatiel.wav
on my mac to make sure my changes still worked. 我在我的mac上重新使用
paplay cockatiel.wav
以确保我的更改仍然有效。 the pulseaudio daemon seems to start on demand, and passes its complaints back to paplay
to be printed on my screen if I made a typo. pulseaudio守护进程似乎是按需启动的,并且如果我
paplay
了, paplay
它的投诉传回paplay
,然后打印在我的屏幕上。 I still have sound with those changes to default.pa, so I'm satisfied that my changes didn't break anything. 我仍然对default.pa的更改有声音,所以我很满意我的更改没有破坏任何东西。
Next, I ran the pulseaudio client in a container like this: 接下来,我在一个像这样的容器中运行pulseaudio客户端:
docker run --rm -v $HOME:$HOME -w $HOME -it \
-e PULSE_SERVER=192.168.10.23 \
-e HOME=$HOME --entrypoint paplay \
jess/pulseaudio $HOME/cockatiel.wav
What this does is run a container with my local home directory as a volume. 这样做是使用我的本地主目录作为卷运行容器。 This serves two purposes.
这有两个目的。 The first is the fact that my cockatiel.wav is located inside
$HOME
. 首先是我的cockatiel.wav位于
$HOME
内部。 The second is because both the client and the server need to have a copy of the same ~/.config/pulse/cookie
file (per that archlinux wiki guide). 第二个是因为客户端和服务器都需要具有相同的
~/.config/pulse/cookie
文件的副本(根据archlinux wiki指南)。
The PULSE_SERVER
environment variable is the en0 IP address of my OSX host, so paplay knows what to connect to. PULSE_SERVER
环境变量是我的OSX主机的en0 IP地址,因此paplay知道连接到什么。
The HOME
environment variable is necessary so paplay can find the same ~/.config/pulse/cookie
file. HOME
环境变量是必需的,因此paplay可以找到相同的~/.config/pulse/cookie
文件。
I was able to play sound from a container running on my docker-for-mac via pulseaudio. 我能够通过pulseaudio从我的docker-for-mac上运行的容器中播放声音。
As long as you get the ~/.config/pulse/cookie
file to appear in the correct location, you should be able to play sound. 只要您将
~/.config/pulse/cookie
文件显示在正确的位置,您就应该能够播放声音。 You don't have to use a host volume to accomplish this-- you could also do a 'docker cp', or even COPY
it into an image. 您不必使用主机卷来完成此操作 - 您还可以执行“docker cp”,甚至将其
COPY
到图像中。
Install PulseAudio on the Mac: 在Mac上安装PulseAudio :
brew install pulseaudio
Run the daemon: 运行守护进程:
pulseaudio --load=module-native-protocol-tcp --exit-idle-time=-1 --daemon
In your Docker container: 在您的Docker容器中:
apt-get install pulseaudio
. apt-get install pulseaudio
。 ENV PULSE_SERVER=docker.for.mac.localhost
ENV PULSE_SERVER=docker.for.mac.localhost
When you run it, share your ~/.config/pulse
directory with the container for authentication. 运行它时,与容器共享
~/.config/pulse
目录以进行身份验证。
You can run a test to see if it's working like this: 您可以运行测试以查看它是否像这样工作:
docker run -it -e PULSE_SERVER=docker.for.mac.localhost -v ~/.config/pulse:/home/pulseaudio/.config/pulse --entrypoint speaker-test --rm jess/pulseaudio -c 2 -l 1 -t wav
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.