Skip to content

Commit 13ca60e

Browse files
geripgeriwernight
authored andcommitted
Dockerfile modified to use the native pulseaudo instead of pulseaudio over network.
This is experimental.
1 parent e2188c3 commit 13ca60e

File tree

3 files changed

+100
-56
lines changed

3 files changed

+100
-56
lines changed

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ COPY entrypoint.sh /entrypoint.sh
3939
# Default configuration.
4040
COPY mopidy.conf /var/lib/mopidy/.config/mopidy/mopidy.conf
4141

42+
# Copy the pulse-client configuratrion.
43+
COPY pulse-client.conf /etc/pulse/client.conf
44+
4245
# Allows any user to run mopidy, but runs by default as a randomly generated UID/GID.
4346
ENV HOME=/var/lib/mopidy
4447
RUN set -ex \

README.md

+88-56
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
[![](https://images.microbadger.com/badges/image/wernight/mopidy.svg)](http://microbadger.com/images/wernight/mopidy "Get your own image badge on microbadger.com")
22

3-
Containerized [**Mopidy**](https://www.mopidy.com/) music server with support for [MPD clients](https://docs.mopidy.com/en/latest/clients/mpd/) and [HTTP clients](https://docs.mopidy.com/en/latest/ext/web/#ext-web).
3+
What is Mopidy?
4+
===============
45

6+
[**Mopidy**](https://www.mopidy.com/) is a music server with support for [MPD clients](https://docs.mopidy.com/en/latest/clients/mpd/) and [HTTP clients](https://docs.mopidy.com/en/latest/ext/web/#ext-web).
57

6-
### Features
8+
Features of this image
9+
----------------------
710

811
* Follows [official installation](https://docs.mopidy.com/en/latest/installation/debian/) on top of [Debian](https://registry.hub.docker.com/_/debian/).
912
* With backend extensions for:
@@ -17,19 +20,47 @@ Containerized [**Mopidy**](https://www.mopidy.com/) music server with support fo
1720
You may install additional [backend extensions](https://docs.mopidy.com/en/latest/ext/backends/).
1821

1922

20-
### Usage
23+
Usage
24+
-----
25+
26+
### Playing sound from the container
27+
28+
There are various ways to have the audio from Mopidy running in your container
29+
to play on your system's audio output. Here are various ways, try them and find
30+
which one works for you.
31+
32+
#### /dev/snd
33+
34+
Simplest is by adding docker argument: `--device /dev/snd`. Try via:
35+
36+
$ docker run --rm \
37+
--device /dev/snd \
38+
wernight/mopidy \
39+
gst-launch-1.0 audiotestsrc ! audioresample ! autoaudiosink
40+
41+
#### PulseAudio native
42+
43+
Mount the current user's pulse directory to the pulseuadio user (UID `105`).
44+
Based on https://github.com/TheBiggerGuy/docker-pulseaudio-example.
45+
46+
$ docker run --rm \
47+
-v /run/user/$UID/pulse:/run/user/105/pulse \
48+
wernight/mopidy \
49+
gst-launch-1.0 audiotestsrc ! audioresample ! autoaudiosink
2150

2251
#### PulseAudio over network
2352

24-
First to make [audio work from within a Docker container](http://stackoverflow.com/q/28985714/167897), you should enable [PulseAudio over network](https://wiki.freedesktop.org/www/Software/PulseAudio/Documentation/User/Network/); so if you have X11 you may for example do:
53+
First to make [audio work from within a Docker container](http://stackoverflow.com/q/28985714/167897),
54+
you should enable [PulseAudio over network](https://wiki.freedesktop.org/www/Software/PulseAudio/Documentation/User/Network/);
55+
so if you have X11 you may for example do:
2556

2657
1. Install [PulseAudio Preferences](http://freedesktop.org/software/pulseaudio/paprefs/). Debian/Ubuntu users can do this:
2758

2859
$ sudo apt-get install paprefs
2960

3061
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).
3162

32-
3. Restart PulseAudio
63+
3. Restart PulseAudio:
3364

3465
$ sudo service pulseaudio restart
3566

@@ -38,82 +69,83 @@ First to make [audio work from within a Docker container](http://stackoverflow.c
3869
$ pulseaudio -k
3970
$ pulseaudio --start
4071

41-
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`.
72+
Note: 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`.
4273

43-
#### General usage
44-
45-
$ docker run -d \
46-
-e "PULSE_SERVER=tcp:$(hostname -i):4713" \
47-
-e "PULSE_COOKIE_DATA=$(pax11publish -d | grep --color=never -Po '(?<=^Cookie: ).*')" \
48-
-v "$PWD/media:/var/lib/mopidy/media:ro" \
49-
-v "$PWD/local:/var/lib/mopidy/local" \
50-
-p 6600:6600 -p 6680:6680 \
51-
--user $UID:$GID \
52-
wernight/mopidy \
53-
mopidy \
54-
-o spotify/username=USERNAME -o spotify/password=PASSWORD \
55-
-o gmusic/username=USERNAME -o gmusic/password=PASSWORD \
56-
-o soundcloud/auth_token=TOKEN
57-
58-
See [mopidy's command](https://docs.mopidy.com/en/latest/command/) for possible additional options.
59-
60-
Most elements are optional (see some examples below). Replace `USERNAME`, `PASSWORD`, `TOKEN` accordingly if needed, or disable services (e.g., `-o spotify/enabled=false`):
61-
62-
* For *Spotify* you'll need a *Premium* account.
63-
* For *Google Music* use your Google account (if you have *2-Step Authentication*, generate an [app specific password](https://security.google.com/settings/security/apppasswords)).
64-
* For *SoundCloud*, just [get a token](https://www.mopidy.com/authenticate/) after registering.
65-
66-
Ports:
67-
68-
* 6600 - MPD server (if you use for example ncmpcpp client)
69-
* 6680 - HTTP server (if you use your browser as client)
70-
71-
Environment variables:
74+
Now set the environment variables:
7275

7376
* `PULSE_SERVER` - PulseAudio server socket.
7477
* `PULSE_COOKIE_DATA` - Hexadecimal encoded PulseAudio cookie commonly at `~/.config/pulse/cookie`.
7578

76-
Volumes:
79+
Example to check it works:
7780

78-
* `/var/lib/mopidy/media` - Path to directory with local media files (optional).
79-
* `/var/lib/mopidy/local` - Path to directory to store local metadata such as libraries and playlists in (optional).
81+
$ docker run --rm \
82+
-e "PULSE_SERVER=tcp:$(hostname -i):4713" \
83+
-e "PULSE_COOKIE_DATA=$(pax11publish -d | grep --color=never -Po '(?<=^Cookie: ).*')" \
84+
wernight/mopidy \
85+
gst-launch-1.0 audiotestsrc ! audioresample ! autoaudiosink
8086

81-
User:
87+
### General usage
8288

83-
* You may run as any UID/GID, and by default it'll run as UID/GID `84044` (`mopidy:audio` from within the container).
84-
The only restriction is if you want to read local media files: That the user (UID) you run as should have read access to these files.
89+
$ docker run -d \
90+
$PUT_HERE_EXRA_DOCKER_ARGUMENTS_FOR_AUDIO_TO_WORK \
91+
-v "$PWD/media:/var/lib/mopidy/media:ro" \
92+
-v "$PWD/local:/var/lib/mopidy/local" \
93+
-p 6600:6600 -p 6680:6680 \
94+
--user $UID:$GID \
95+
wernight/mopidy \
96+
mopidy \
97+
-o spotify/username=USERNAME -o spotify/password=PASSWORD \
98+
-o gmusic/username=USERNAME -o gmusic/password=PASSWORD \
99+
-o soundcloud/auth_token=TOKEN
100+
101+
Most arguments are optional (see some examples below):
102+
103+
* Docker arguments:
104+
* `$PUT_HERE_EXRA_DOCKER_ARGUMENTS_FOR_AUDIO_TO_WORK` should be replaced
105+
with some arguments that work to play audio from within the docker
106+
container as tested above.
107+
* `-v ...:/var/lib/mopidy/media:ro` - (optional) Path to directory with local media files.
108+
* `-v ...:/var/lib/mopidy/local` - (optional) Path to directory to store local metadata such as libraries and playlists in.
109+
* `-p 6600:6600` - (optional) Exposes MPD server (if you use for example ncmpcpp client).
110+
* `-p 6680:6680` - (optional) Exposes HTTP server (if you use your browser as client).
111+
* `--user $UID:$GID` - (optional) You may run as any UID/GID, and by default it'll run as UID/GID `84044` (`mopidy:audio` from within the container).
112+
The main restriction is if you want to read local media files: That the user (UID) you run as should have read access to these files.
113+
Similar for other mounts. If you have issues, try first as `--user root`.
114+
* Mopidy arguments (see [mopidy's command](https://docs.mopidy.com/en/latest/command/) for possible additional options),
115+
replace `USERNAME`, `PASSWORD`, `TOKEN` accordingly if needed, or disable services (e.g., `-o spotify/enabled=false`):
116+
* For *Spotify* you'll need a *Premium* account.
117+
* For *Google Music* use your Google account (if you have *2-Step Authentication*, generate an [app specific password](https://security.google.com/settings/security/apppasswords)).
118+
* For *SoundCloud*, just [get a token](https://www.mopidy.com/authenticate/) after registering.
85119

86120
##### Example using HTTP client to stream local files
87121

88122
1. Give read access to your audio files to user **84044**, group **84044**, or all users (e.g., `$ chgrp -R 84044 $PWD/media && chmod -R g+rX $PWD/media`).
89123
2. Index local files:
90124

91125
$ docker run --rm \
92-
-e "PULSE_SERVER=tcp:$(hostname -i):4713" \
93-
-e "PULSE_COOKIE_DATA=$(pax11publish -d | grep --color=never -Po '(?<=^Cookie: ).*')" \
94-
-v "$PWD/media:/var/lib/mopidy/media:ro" \
95-
-v "$PWD/local:/var/lib/mopidy/local" \
96-
-p 6680:6680 \
97-
wernight/mopidy mopidy local scan
126+
--device /dev/snd \
127+
-v "$PWD/media:/var/lib/mopidy/media:ro" \
128+
-v "$PWD/local:/var/lib/mopidy/local" \
129+
-p 6680:6680 \
130+
wernight/mopidy mopidy local scan
98131

99132
3. Start the server:
100133

101134
$ docker run -d \
102-
-e "PULSE_SERVER=tcp:$(hostname -i):4713" \
103-
-e "PULSE_COOKIE_DATA=$(pax11publish -d | grep --color=never -Po '(?<=^Cookie: ).*')" \
104-
-v "$PWD/media:/var/lib/mopidy/media:ro" \
105-
-v "$PWD/local:/var/lib/mopidy/local" \
106-
-p 6680:6680 \
107-
wernight/mopidy
135+
-e "PULSE_SERVER=tcp:$(hostname -i):4713" \
136+
-e "PULSE_COOKIE_DATA=$(pax11publish -d | grep --color=never -Po '(?<=^Cookie: ).*')" \
137+
-v "$PWD/media:/var/lib/mopidy/media:ro" \
138+
-v "$PWD/local:/var/lib/mopidy/local" \
139+
-p 6680:6680 \
140+
wernight/mopidy
108141

109142
4. Browse to http://localhost:6680/
110143

111144
#### Example using [ncmpcpp](https://docs.mopidy.com/en/latest/clients/mpd/#ncmpcpp) MPD console client
112145

113146
$ docker run --name mopidy -d \
114-
-e "PULSE_SERVER=tcp:$(hostname -i):4713" \
115-
-e "PULSE_COOKIE_DATA=$(pax11publish -d | grep --color=never -Po '(?<=^Cookie: ).*')" \
116-
wernight/mopidy
147+
-v /run/user/$UID/pulse:/run/user/105/pulse \
148+
wernight/mopidy
117149
$ docker run --rm -it --link mopidy:mopidy wernight/ncmpcpp ncmpcpp --host mopidy
118150

119151

pulse-client.conf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Connect to the host's server using the mounted UNIX socket
2+
default-server = unix:/run/user/105/pulse/native
3+
4+
# Prevent a server running in the container
5+
autospawn = no
6+
daemon-binary = /bin/true
7+
8+
# Prevent the use of shared memory
9+
enable-shm = false

0 commit comments

Comments
 (0)