在泊坞窗容器使用音频应用程序运行 [英] run apps using audio in a docker container

查看:177
本文介绍了在泊坞窗容器使用音频应用程序运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是由启发你可以运行在泊坞窗容器GUI应用?

其基本思想是运行具有音频和UI(VLC,火狐,SKYPE,...)

The basic idea is to run apps with audio and ui (vlc, firefox, skype, ...)

我正在寻找使用了PulseAudio泊坞窗容器,但所有的容器,我发现用在哪里流的PulseAudio通过TCP。
(应用程序安全沙箱)

I was searching for docker containers using pulseaudio but all containers I found where using pulseaudio streaming over tcp. (security sandboxing of the applications)

在我来说,我会prefere从应用程序直接播放音频容器内到我的主机的pulseaudio。 (不SSH隧道和臃肿泊坞窗图片)

In my case I would prefere playing audio from an app inside the container directly to my host pulseaudio. (without ssh tunneling and bloated docker images)

pulseaudio的,因为我的Qt应用程序使用它;)

Pulseaudio because my qt app is using it ;)

推荐答案

我花了一些时间,直到我发现需要什么。 (Ubuntu的)

it took me some time until i found out what is needed. (Ubuntu)

我们先从泊坞窗运行命令泊坞窗运行-ti --rm myContainer中的sh -c回声运行的东西

we start with the docker run command docker run -ti --rm myContainer sh -c "echo run something"

ALSA:结果
我们需要的/ dev / SND 和一些硬件的访问,因为它看起来像。
当我们把这个在一起,我们有

ALSA:
we need /dev/snd and some hardware access as it looks like. when we put this together we have

docker run -ti --rm \
    -v /dev/snd:/dev/snd \
    --lxc-conf='lxc.cgroup.devices.allow = c 116:* rwm' \
    myContainer sh -c "echo run something"`

的PulseAudio:结果
在这里我们需要基本的/ dev / shm的的/ etc /机器ID /运行/用户/ $ UID /脉冲。但是,这并不是所有的(因为的Ubuntu也许,以及他们如何做到了过去)。该envirorment变量 XDG_RUNTIME_DIR 必须在主机系统和在码头工人的容器一样。您可能还需要的/ var / lib中/ DBUS ,因为一些应用程序正在访问从这里机器ID(可能只包含一个符号链接到真正的机器ID)。至少,你可能需要隐藏的主文件夹〜/ .pulse 对于一些临时数据(我不知道这个)。

PULSEAUDIO:
Here we need basically /dev/shm, /etc/machine-id and /run/user/$uid/pulse. But that is not all (maybe because of Ubuntu and how they did it in the past). The envirorment variable XDG_RUNTIME_DIR has to be the same in the host system and in your docker container. You may also need /var/lib/dbus because some apps are accessing the machine id from here (may only containing a symbolic link to the 'real' machine id). And at least you may need the hidden home folder ~/.pulse for some temp data (i am not sure about this).

docker run -ti --rm \
    -v /dev/shm:/dev/shm \
    -v /etc/machine-id:/etc/machine-id \
    -v /run/user/$uid/pulse:/run/user/$uid/pulse \
    -v /var/lib/dbus:/var/lib/dbus \
    -v ~/.pulse:/home/$dockerUsername/.pulse \
    myContainer sh -c "echo run something"

当然,你可以结合在一起既与的Xserver UI转发喜欢这里一起使用它:<一href=\"http://stackoverflow.com/a/28971413/2835523\">http://stackoverflow.com/a/28971413/2835523

Of course you can combine both together and use it together with xServer ui forwarding like here: http://stackoverflow.com/a/28971413/2835523

仅举:


  • 您可以处理其中的大部分(所有没有使用的ID)的 dockerfile

  • 使用的uid = $(ID -u)来获取用户的ID和GID与 ID -g

  • 具有此ID创建一个泊坞窗的用户

  • you can handle most of this (all without the used id) in the dockerfile
  • using uid=$(id -u) to get the user id and gid with id -g
  • creating a docker user with this id

创建用户脚本:

mkdir -p /home/$dockerUsername && \
echo "$dockerUsername:x:${uid}:${gid}:$dockerUsername,,,:/home/$dockerUsername:/bin/bash" >> /etc/passwd && \
echo "$dockerUsername:x:${uid}:" >> /etc/group && \
mkdir /etc/sudoers.d && \
echo "$dockerUsername ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$dockerUsername && \
chmod 0440 /etc/sudoers.d/$dockerUsername && \
chown ${uid}:${gid} -R /home/$dockerUsername

这篇关于在泊坞窗容器使用音频应用程序运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆