我正在使用主机Ubuntu 16.0.4
系统运行我的 lxc 容器。我卸载了它,pulseaudio
因为我想直接使用 ALSA。
从主机卸载 pulseaudio 后,我可以使用以下命令播放声音(在主机上):
aplay /usr/share/sounds/alsa/Rear_Right.wav
在 中lxc container
,我安装了alsa libs
和alsa utils
。当我在容器内使用与上述相同的命令时,出现以下错误:
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4248:(_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:4248:(_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:4248:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4727:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default
aplay: main:654: audio open error: No such file or directory
容器内的声音设备有:
bash-4.2# ls -al /dev/snd/*
crw-rw---- 1 root 29 116, 5 Nov 1 17:21 /dev/snd/controlC0
crw-rw---- 1 root 29 116, 2 Nov 1 17:21 /dev/snd/controlC1
crw-rw---- 1 root 29 116, 10 Nov 1 17:21 /dev/snd/controlC2
crw-rw---- 1 root 29 116, 9 Nov 1 17:21 /dev/snd/hwC0D0
crw-rw---- 1 root 29 116, 13 Nov 1 17:21 /dev/snd/hwC2D0
crw-rw---- 1 root 29 116, 6 Nov 1 17:21 /dev/snd/pcmC0D3p
crw-rw---- 1 root 29 116, 7 Nov 1 17:21 /dev/snd/pcmC0D7p
crw-rw---- 1 root 29 116, 8 Nov 1 17:21 /dev/snd/pcmC0D8p
crw-rw---- 1 root 29 116, 4 Nov 1 17:21 /dev/snd/pcmC1D0c
crw-rw---- 1 root 29 116, 3 Nov 1 17:27 /dev/snd/pcmC1D0p
crw-rw---- 1 root 29 116, 11 Nov 1 17:21 /dev/snd/pcmC2D3p
crw-rw---- 1 root 29 116, 12 Nov 1 17:21 /dev/snd/pcmC2D7p
crw-rw---- 1 root 29 116, 1 Nov 1 17:21 /dev/snd/seq
crw-rw---- 1 root 29 116, 33 Nov 1 17:21 /dev/snd/timer
/dev/snd/by-id:
total 0
drwxr-xr-x 2 root root 60 Nov 1 17:21 .
drwxr-xr-x 4 root root 360 Nov 1 17:21 ..
lrwxrwxrwx 1 root root 12 Nov 1 17:21 usb-126c_4.1_amplifier-00 -> ../controlC1
/dev/snd/by-path:
total 0
drwxr-xr-x 2 root root 100 Nov 1 17:21 .
drwxr-xr-x 4 root root 360 Nov 1 17:21 ..
lrwxrwxrwx 1 root root 12 Nov 1 17:21 pci-0000:00:03.0 -> ../controlC0
lrwxrwxrwx 1 root root 12 Nov 1 17:21 pci-0000:00:14.0-usb-0:5:1.0 -> ../controlC1
lrwxrwxrwx 1 root root 12 Nov 1 17:21 pci-0000:01:00.1 -> ../controlC2
答案1
我终于能够在lxc
容器内播放声音了。
首先,我必须确保已为声音设备启用 lxc 设备 cgroup。您可以通过在容器config
文件中添加以下内容来执行此操作:
#Sound device nodes
lxc.cgroup.devices.allow = c 116:* rwm
lxc.mount.entry = /dev/snd dev/snd none bind,optional,create=dir
接下来,由于我ALSA
在主机系统上使用来播放声音,并且想在里面再次使用 alsa lxc container
,请确保alsa
配置文件已复制到容器内。
我从主机复制了 alsa 配置文件到容器/etc/asound.conf
内部lxc
。这样做的原因是alsalib
容器内部必须具有与主机相同的配置。
此后,我就能够在容器内播放声音了。我通过运行以下命令进行了测试:
aplay /usr/share/sounds/alsa/Rear_Right.wav