Fix audio within container.

This commit is contained in:
Werner Beroux
2015-04-27 14:52:11 +02:00
parent 71ab329e4e
commit 4768d79ac6
3 changed files with 44 additions and 7 deletions

View File

@@ -28,13 +28,16 @@ RUN pip install \
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Run as mopidy user
#RUN useradd --system --uid 377 -M --shell /usr/sbin/nologin mopidy
USER mopidy
# Default configuration
RUN mkdir -p ~/.config/mopidy
ADD mopidy.conf /var/lib/mopidy/.config/mopidy/mopidy.conf
RUN chown mopidy:audio -R /var/lib/mopidy/.config
# Start helper script
ADD mopidy.sh /mopidy.sh
RUN chown mopidy:audio /mopidy.sh
# Run as mopidy user
USER mopidy
VOLUME /var/lib/mopidy/local
VOLUME /var/lib/mopidy/media
@@ -42,4 +45,4 @@ VOLUME /var/lib/mopidy/media
EXPOSE 6600
EXPOSE 6680
ENTRYPOINT ["/usr/bin/mopidy"]
ENTRYPOINT ["/mopidy.sh"]

View File

@@ -22,10 +22,30 @@ You may install additional [backend extensions](https://docs.mopidy.com/en/lates
Usage
-----
First for [audio in a docker container](http://stackoverflow.com/q/28985714/167897) to work, enabled [PulseAudio over network](https://wiki.freedesktop.org/www/Software/PulseAudio/Documentation/User/Network/). If you have X11 you may for example do:
1. Install [PulseAudio Preferences](http://freedesktop.org/software/pulseaudio/paprefs/). Debian/Ubuntu users can do this:
$ sudo apt-get install paprefs
2. Launch `paprefs` (PulseAudio Preferences) > "*Network Server*" tab > Check "*Enable network access to local sound devices*" (you may check "*Don't require authentication*" to avoid mounting cookie file described below).
3. Restart PulseAudio
$ sudo service pulseaudio restart
or
$ pulseaudio -k
$ pulseaudio --start
On some distributions, it may be necessary to completely restart your computer. You can confirm that the settings have successfully been applied running `pax11publish | grep -Eo 'tcp:[^ ]*'`. You should see something like `tcp:myhostname:4713`.
General usage (see [mopidy commands](https://docs.mopidy.com/en/latest/command/)):
$ docker run -d \
-v /dev/snd:/dev/snd --lxc-conf='lxc.cgroup.devices.allow = c 116:* rwm' \
-e PULSE_SERVER=tcp:$(hostname -i):4713 \
-e PULSE_COOKIE_DATA=$(pax11publish -d | grep --color=never -Po '(?<=^Cookie: ).*') \
-v $PWD/media:/var/lib/mopidy/media:ro \
-v $PWD/local:/var/lib/mopidy/local \
-p 6600:6600 -p 6680:6680 \
@@ -45,6 +65,11 @@ Ports:
* 6600 - MPD server
* 6680 - HTTP server
Environment variables:
* `PULSE_SERVER` - PulseAudio server socket.
* `PULSE_COOKIE_DATA` - Hexadecimal encoded PulseAudio cookie commonly at `~/.config/pulse/cookie`.
Volumes:
* `/var/lib/mopidy/media` - Path to directory with local media files (optional).

9
mopidy.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
if [[ "$PULSE_COOKIE_DATA" != "" ]]
then
echo -ne $(echo $PULSE_COOKIE_DATA | sed -e 's/../\\x&/g') >$HOME/pulse.cookie
export PULSE_COOKIE=$HOME/pulse.cookie
fi
exec /usr/bin/mopidy $*