【问题标题】:How to play sound in a Docker container on Mac OS Yosemite如何在 Mac OS Yosemite 上的 Docker 容器中播放声音
【发布时间】:2017-04-26 06:58:51
【问题描述】:

我正在尝试将文本转语音应用程序 docker 化以与其他开发人员共享代码,但是我现在遇到的问题是 docker 容器在我的主机上找不到声卡。

当我尝试在我的 docker 容器中播放 wav 文件时

root@3e9ef1e869ea:/# aplay Alesis-Fusion-Acoustic-Bass-C2.wav
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default
aplay: main:722: audio open error: No such file or directory

我猜主要问题是 docker 容器无法访问我主机上的声卡。

到现在为止

  1. 我在我的内部安装了 alsa-utils 和大多数 alsa 依赖项 码头集装箱。
  2. 在运行时添加了--group-add audio 容器通过指定docker run --group-add audio -t -i self/debian /bin/bash

我不确定 docker 是否可以做到这一点(我不确定声卡等硬件资源是如何与容器共享的)。我在 Mac OS Yosemite 主机上使用 debian 容器。

【问题讨论】:

标签: audio docker alsa


【解决方案1】:

绝对有可能,你需要挂载/dev/snd,看看Jess Frazelle如何启动一个Spotify容器,来自

https://blog.jessfraz.com/post/docker-containers-on-the-desktop/

你会注意到

docker run -it \
    -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket
    -e DISPLAY=unix$DISPLAY \ # pass the display
    --device /dev/snd \ # sound
    --name spotify \
    jess/spotify

或者对于 Chrome,最后

docker run -it \
    --net host \ # may as well YOLO
    --cpuset-cpus 0 \ # control the cpu
    --memory 512mb \ # max memory it can use
    -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket
    -e DISPLAY=unix$DISPLAY \ # pass the display
    -v $HOME/Downloads:/root/Downloads \ # optional, but nice
    -v $HOME/.config/google-chrome/:/data \ # if you want to save state
    --device /dev/snd \ # so we have sound
    --name chrome \
    jess/chrome

【讨论】:

  • 你知道如何让它在作为主机的 Windows 上运行吗?具体来说,Windows 上的 SND 设备替代方案是什么?
  • 有什么建议可以在windows上做同样的事情吗?
  • 这对 JACK 有效吗?我是否需要在容器中安装任何音频软件(ALSA、pulseaudio 或 JACK),还是将它们安装在主机中就足够了?
  • Windows 上--device /dev/snd 的等价物是什么?
  • 至于 OP,我也在运行 MacOS,我的 mac 上没有 /dev/snd 文件。码头工人的答案是:docker: Error response from daemon: error gathering device information while adding custom device "/dev/snd": no such file or directory.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多