Closed li-fang closed 3 years ago
俺也一样
audio Success!enjoy! video error! the study...
Linux ThinkPad 5.8.0-41-generic #46~20.04.1-Ubuntu SMP Mon Jan 18 17:52:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux Docker version 20.10.2, build 2291f61 docker-compose version 1.28.0, build d02a7b1a
version: "3"
services:
wechat:
image: bestwu/wechat
container_name: wechat
#privileged: true
devices:
- /dev/snd
#- /dev/video0 #然并卵
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
- $HOME/桌面/WeChatFiles:/WeChatFiles
- ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native
- $HOME/.config/pulse/cookie:/root/.config/pulse/cookie #我不知道为什么需要cookie。没有cookie,就会发生错误ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Access denied
environment:
- DISPLAY=unix$DISPLAY
- QT_IM_MODULE=fcitx
- XMODIFIERS=@im=fcitx
- GTK_IM_MODULE=fcitx
###解决声音设备访问权限问题
# 设置PULSE_SERVER以便让容器的pulseaudio知道服务器地址。
# apt update && apt install alsa-base alsa-utils pulseaudio
- PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native
# 添加容器到该audio组,或AUDIO_GID=xx,查看:cat /etc/group|grep audio
- AUDIO_GID=$(getent group audio|cut -d: -f3)
#- VIDEO_GID=44 # 可选(然并卵) 查看:cat /etc/group | grep video 主机video gid 解决视频设备访问权限问题
- GID=1000 # 可选 默认1000 主机当前用户 gid 解决挂载目录访问权限问题
- UID=1000 # 可选 默认1000 主机当前用户 uid 解决挂载目录访问权限问题
ipc: host
Pulseaudio Please refer to https://github.com/mviereck/x11docker/wiki/Container-sound:-ALSA-or-Pulseaudio
希望对别人有帮助, 在20.04, 22.04下测试后都有声音
初次启用使用脚本:
rm -rf /tmp/pulseaudio.socket
rm -rf /tmp/pulseaudio.client.conf
pactl load-module module-native-protocol-unix socket=/tmp/pulseaudio.socket
cat <<EOT >> /tmp/pulseaudio.client.conf
default-server = unix:/tmp/pulseaudio.socket
# Prevent a server running in the container
autospawn = no
daemon-binary = /bin/true
# Prevent the use of shared memory
enable-shm = false
EOT
xhost +
docker run -d --device /dev/snd --ipc=host \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v $HOME/WeChatFiles:/WeChatFiles \
-v /tmp/pulseaudio.socket:/tmp/pulseaudio.socket \
-v /tmp/pulseaudio.client.conf:/etc/pulse/client.conf \
-e DISPLAY=unix$DISPLAY \
-e XMODIFIERS=@im=fcitx \
-e QT_IM_MODULE=fcitx \
-e GTK_IM_MODULE=fcitx \
-e PULSE_SERVER=unix:/tmp/pulseaudio.socket \
-e PULSE_COOKIE=/tmp/pulseaudio.cookie \
-e AUDIO_GID=`getent group audio | cut -d: -f3` \
-e GID=`id -g` \
-e UID=`id -u` \
--name wechat \
bestwu/wechat
xhost -
在container 创建之后不需要每次使用run,因为run = create + start. 如果使用run 每次都会创建一个新的container. 改使用脚本
rm -rf /tmp/pulseaudio.socket
rm -rf /tmp/pulseaudio.client.conf
pactl load-module module-native-protocol-unix socket=/tmp/pulseaudio.socket
cat <<EOT >> /tmp/pulseaudio.client.conf
default-server = unix:/tmp/pulseaudio.socket
# Prevent a server running in the container
autospawn = no
daemon-binary = /bin/true
# Prevent the use of shared memory
enable-shm = false
EOT
xhost +
docker stop wechat
docker start wechat
xhost -
资源: https://github.com/mviereck/x11docker/wiki/Container-sound:-ALSA-or-Pulseaudio
感谢分享!目前使用良好,除了语音消息没声音,视频也没有声音。AUDIO_ID已经改成本地查到的,是否是因为dockerfile里面的AUDIO_ID也需要改呢