Ubuntu Container - is it possible to have audio in a container

titust11

Member
Nov 18, 2021
48
4
8
65
Hi
I've created an Ubuntu 22.04 container (not Docker). My MTB has a Realtek ALC1150, onboard.
I'm wondering if I can passthrough the audio crtl. to the container (I plan to install Pianobar a CLI based client of Pandora music streaming).
I've done that in the past with with a VM, but I can't find a way to do it with a container.
Or I can install a USB to Audio dongle on the machine and maybe it's easier to passthrough an USB Audio device
Thanks
 
Last edited:
Code:
root@pve:~# ls -l /dev/snd
total 0
drwxr-xr-x 2 root root       60 Jul 15 20:00 by-path
crw-rw---- 1 root audio 116,  8 Jul 15 20:00 controlC0
crw-rw---- 1 root audio 116,  6 Jul 15 20:00 hwC0D0
crw-rw---- 1 root audio 116,  7 Jul 15 20:00 hwC0D2
crw-rw---- 1 root audio 116,  3 Jul 15 20:00 pcmC0D0c
crw-rw---- 1 root audio 116,  2 Jul 15 20:00 pcmC0D0p
crw-rw---- 1 root audio 116,  4 Jul 15 20:00 pcmC0D1p
crw-rw---- 1 root audio 116,  5 Jul 15 20:00 pcmC0D2c
crw-rw---- 1 root audio 116,  1 Jul 15 19:58 seq
crw-rw---- 1 root audio 116, 33 Jul 15 19:58 timer
I guess my device class number is 116. So I appended this to my 104.conf file
Code:
lxc.cgroup2.devices.allow: c 116:* rwm
lxc.mount.entry: /dev/snd dev/snd none bind,create=dir
In the container machine I'm able to see the same items in ls -l /dev/snd, but I have no idea how to check the existence / functionality of a sound card.
Code:
arecord -l
arecord: device_list:274: no soundcards found...
 
Last edited:
Code:
arecord -l
arecord: device_list:274: no soundcards found...
Check the permissions. Is your user inside the container a member of the audio group? Did you lxc.idmap the audio group inside the container to the audio group of the host?
In the container machine I'm able to see the same items in ls -l /dev/snd,
What does it look like (ls -l /dev/snd/ and especially look at the permissions)?
but I have no idea how to check the existence / functionality of a sound card.
(I plan to install Pianobar a CLI based client of Pandora music streaming)
I think that a good test would be to see if Pianobar works, but I don't know anything about it.
 
What does it look like (ls -l /dev/snd/ and especially look at the permissions)?
admin@test:/root$ ls -l /dev/snd
total 0
drwxr-xr-x 2 nobody nogroup 60 Jul 16 00:00 by-path
crw-rw---- 1 nobody nogroup 116, 8 Jul 16 00:00 controlC0
crw-rw---- 1 nobody nogroup 116, 6 Jul 16 00:00 hwC0D0
crw-rw---- 1 nobody nogroup 116, 7 Jul 16 00:00 hwC0D2
crw-rw---- 1 nobody nogroup 116, 3 Jul 16 00:00 pcmC0D0c
crw-rw---- 1 nobody nogroup 116, 2 Jul 16 00:00 pcmC0D0p
crw-rw---- 1 nobody nogroup 116, 4 Jul 16 00:00 pcmC0D1p
crw-rw---- 1 nobody nogroup 116, 5 Jul 16 00:00 pcmC0D2c
crw-rw---- 1 nobody nogroup 116, 1 Jul 15 23:58 seq
crw-rw---- 1 nobody nogroup 116, 33 Jul 15 23:58 timer
 
I currently do this with a USB DAC and a privileged container running Ubuntu. (Not sure if it needs to be privileged.)

Code:
root@pve:~# ls -la /dev/snd/by-id/
total 0
drwxr-xr-x 2 root root  60 Jul 24 16:58 .
drwxr-xr-x 4 root root 180 Jul 24 16:58 ..
lrwxrwxrwx 1 root root  12 Jul 24 16:58 usb-RME_ADI-2_DAC__51090980__0E92A13844401C8-00 -> ../controlC1

root@pve:~# ls -la /dev/snd/
total 0
drwxr-xr-x  4 root root      180 Jul 24 16:58 .
drwxr-xr-x 22 root root     4800 Jul 20 14:39 ..
drwxr-xr-x  2 root root       60 Jul 24 16:58 by-id
drwxr-xr-x  2 root root       60 Jul 24 16:58 by-path
crw-rw----  1 root audio 116,  4 Jul 24 16:58 controlC1
crw-rw----  1 root audio 116,  3 Jul 24 16:58 pcmC1D0c
crw-rw----  1 root audio 116,  2 Jul 24 16:58 pcmC1D0p
crw-rw----  1 root audio 116,  1 Jul 19 06:35 seq
crw-rw----  1 root audio 116, 33 Jul 19 06:35 timer

root@pve:~# cat /etc/pve/lxc/101.conf
arch: amd64
cores: 2
features: nesting=1
hostname: roon
memory: 4096
mp0: /raid/music,mp=/mnt/music
mp1: /raid/backups_roon,mp=/mnt/backups_roon
net0: name=eth0,bridge=vmbr0,firewall=1,hwaddr=56:68:4D:F5:F5:EF,ip=dhcp,ip6=dhcp,type=veth
onboot: 1
ostype: ubuntu
rootfs: local-zfs:subvol-101-disk-0,size=20G
swap: 512
lxc.cgroup2.devices.allow: c 116:* rwm
lxc.mount.entry: /dev/snd dev/snd none bind,optional,create=dir

root@pve:~# pct enter 101
root@roon:~# aplay --list-devices
**** List of PLAYBACK Hardware Devices ****
card 1: DAC51090980 [ADI-2 DAC (51090980)], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
 
Thank you very much sir. Everything was right in my config, with one exception. In my container conf file I had unpriviledged=1. Yours did not have that. I removed the line, and I now can see the audio device:)
So the trick was the priviledged lxc. Thanks again.
Code:
admin@pandora:/$ aplay --list-devices
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC1150 Analog [ALC1150 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 1: ALC1150 Digital [ALC1150 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
 
Last edited:
I currently do this with a USB DAC and a privileged container running Ubuntu. (Not sure if it needs to be privileged.)

Code:
root@pve:~# ls -la /dev/snd/by-id/
total 0
drwxr-xr-x 2 root root  60 Jul 24 16:58 .
drwxr-xr-x 4 root root 180 Jul 24 16:58 ..
lrwxrwxrwx 1 root root  12 Jul 24 16:58 usb-RME_ADI-2_DAC__51090980__0E92A13844401C8-00 -> ../controlC1

root@pve:~# ls -la /dev/snd/
total 0
drwxr-xr-x  4 root root      180 Jul 24 16:58 .
drwxr-xr-x 22 root root     4800 Jul 20 14:39 ..
drwxr-xr-x  2 root root       60 Jul 24 16:58 by-id
drwxr-xr-x  2 root root       60 Jul 24 16:58 by-path
crw-rw----  1 root audio 116,  4 Jul 24 16:58 controlC1
crw-rw----  1 root audio 116,  3 Jul 24 16:58 pcmC1D0c
crw-rw----  1 root audio 116,  2 Jul 24 16:58 pcmC1D0p
crw-rw----  1 root audio 116,  1 Jul 19 06:35 seq
crw-rw----  1 root audio 116, 33 Jul 19 06:35 timer

root@pve:~# cat /etc/pve/lxc/101.conf
arch: amd64
cores: 2
features: nesting=1
hostname: roon
memory: 4096
mp0: /raid/music,mp=/mnt/music
mp1: /raid/backups_roon,mp=/mnt/backups_roon
net0: name=eth0,bridge=vmbr0,firewall=1,hwaddr=56:68:4D:F5:F5:EF,ip=dhcp,ip6=dhcp,type=veth
onboot: 1
ostype: ubuntu
rootfs: local-zfs:subvol-101-disk-0,size=20G
swap: 512
lxc.cgroup2.devices.allow: c 116:* rwm
lxc.mount.entry: /dev/snd dev/snd none bind,optional,create=dir

root@pve:~# pct enter 101
root@roon:~# aplay --list-devices
**** List of PLAYBACK Hardware Devices ****
card 1: DAC51090980 [ADI-2 DAC (51090980)], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
BTW what application are you using to play music on your USB DAC?
 
I currently do this with a USB DAC and a privileged container running Ubuntu. (Not sure if it needs to be privileged.)

Code:
root@pve:~# ls -la /dev/snd/by-id/
total 0
drwxr-xr-x 2 root root  60 Jul 24 16:58 .
drwxr-xr-x 4 root root 180 Jul 24 16:58 ..
lrwxrwxrwx 1 root root  12 Jul 24 16:58 usb-RME_ADI-2_DAC__51090980__0E92A13844401C8-00 -> ../controlC1

root@pve:~# ls -la /dev/snd/
total 0
drwxr-xr-x  4 root root      180 Jul 24 16:58 .
drwxr-xr-x 22 root root     4800 Jul 20 14:39 ..
drwxr-xr-x  2 root root       60 Jul 24 16:58 by-id
drwxr-xr-x  2 root root       60 Jul 24 16:58 by-path
crw-rw----  1 root audio 116,  4 Jul 24 16:58 controlC1
crw-rw----  1 root audio 116,  3 Jul 24 16:58 pcmC1D0c
crw-rw----  1 root audio 116,  2 Jul 24 16:58 pcmC1D0p
crw-rw----  1 root audio 116,  1 Jul 19 06:35 seq
crw-rw----  1 root audio 116, 33 Jul 19 06:35 timer

root@pve:~# cat /etc/pve/lxc/101.conf
arch: amd64
cores: 2
features: nesting=1
hostname: roon
memory: 4096
mp0: /raid/music,mp=/mnt/music
mp1: /raid/backups_roon,mp=/mnt/backups_roon
net0: name=eth0,bridge=vmbr0,firewall=1,hwaddr=56:68:4D:F5:F5:EF,ip=dhcp,ip6=dhcp,type=veth
onboot: 1
ostype: ubuntu
rootfs: local-zfs:subvol-101-disk-0,size=20G
swap: 512
lxc.cgroup2.devices.allow: c 116:* rwm
lxc.mount.entry: /dev/snd dev/snd none bind,optional,create=dir

root@pve:~# pct enter 101
root@roon:~# aplay --list-devices
**** List of PLAYBACK Hardware Devices ****
card 1: DAC51090980 [ADI-2 DAC (51090980)], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
Now I have another issue, when I try to play with pianobar, I get the answer "Cannot open audio device".
 
Now I have another issue, when I try to play with pianobar, I get the answer "Cannot open audio device".
Try this out:
  • Shutdown container.
  • Backup container.
  • Restore container. (Make sure to restore as privileged.)
  • Startup container.
I'm using Roon... But I always test with the alsa utilities.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!