首页 > 解决方案 > Docker NodeJS 运行 pulseaudio --system 无法打开 cookie 文件

问题描述

我正在尝试让 NodeJS 服务器在 Docker 中运行 pulseaudio,以便对 pupeteer 浏览器进行屏幕录制。我已经把多余的部分去掉了,只包含了一个最小的例子来解决我遇到的问题。试图运行pulseaudio --system给出Failed to open cookie file. 我如何事先创建这个文件或让它动态创建它。

Dockerfile

FROM node:14

RUN apt-get update && apt-get install -y pulseaudio
RUN apt-get update && apt-get install -y pulseaudio-module-zeroconf
RUN apt-get update && apt-get install -y dbus-x11

RUN echo "load-module module-native-protocol-tcp auth-anonymous=1" >> /etc/pulse/default.pa
RUN echo "load-module module-zeroconf-publish" >> /etc/pulse/default.pa

COPY . .

CMD bash start_node.sh

start_node.sh

#!/bin/bash
service dbus restart
export $(dbus-launch)
pulseaudio --system

要运行的命令

docker build -t pulseaudio .
docker run -it --rm pulseaudio

输出

[ ok ] Stopping system message bus: dbus.
[ ok ] Starting system message bus: dbus.
W: [pulseaudio] main.c: Running in system mode, but --disallow-exit not set.
W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set.
N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode.
N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time.
W: [pulseaudio] main.c: OK, so you are running PA in system mode. Please make sure that you actually do want to do that.W: [pulseaudio] main.c: Please read http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/ for an explanation why system mode is usually a bad idea.
W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.config/pulse/cookie': No such file or directory
W: [pulseaudio] authkey.c: Failed to load authentication key '/var/run/pulse/.config/pulse/cookie': No such file or directory
W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.pulse-cookie': No such file or directory
W: [pulseaudio] authkey.c: Failed to load authentication key '/var/run/pulse/.pulse-cookie': No such file or directory

标签: node.jsdockerpulseaudio

解决方案


如果您使用 root 用户来使其工作,您需要启动 PulseAudio 守护程序。

将行更改为 pulseaudio -D --system


推荐阅读