Search code examples
node.jsdockerpulseaudio

Docker NodeJS run pulseaudio --system Failed to open cookie file


I'm trying to get a NodeJS server running pulseaudio inside Docker for the purposes of screen recording a pupeteer browser. I've left the extra bits off and just included a minimal example to get to where I'm stuck. Trying to run pulseaudio --system gives Failed to open cookie file. How do I create this file before hand or get it to create it on the fly.

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

Commands to run

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

Output

[ 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

Solution

  • If you are using to root user in order to get it to work, you need to start the PulseAudio daemon.

    Change the line to pulseaudio -D --system