主要参考这里
关键参考这里
1. 确认声卡名字
sudo apt install alsa-utils
aplay -l 查看声卡名字
card 1: Generic [HD-Audio Generic], device 0: ALC287 Analog [ALC287 Analog]
Subdevices: 0/1
Subdevice #0: subdevice #0
声卡名字是 Generic
2. 起一个容器
docker pull ubuntu:20.04
docker run -it --privileged --device /dev/snd --env ALSA_CARD=Generic --name test 33985b2ba010 /bin/bash
# docker stop test && docker rm test
apt update
apt install vim alsa-utils
3. 配置文件
vim /etc/asound.conf
pcm.!default{
type hw
card 1
device 0
}
ctl.!default{
type hw
card 1
device 0
}
timer.!default{
type hw
card 1
device 0
}
4. 安装播放器,测试音频
apt install sox libsox-fmt-all
play xxx.mp3