• Stars
    star
    155
  • Rank 233,708 (Top 5 %)
  • Language
    Dockerfile
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Containerized Mopidy MPD (Music Player Daemon) along with Spotify, Google Music... plugins.

What is Mopidy?

Mopidy is a music server with support for MPD clients and HTTP clients.

Features of this image

You may install additional backend extensions.

Usage

Playing sound from the container

There are various ways to have the audio from Mopidy running in your container to play on your system's audio output. Here are various ways, try them and find which one works for you.

/dev/snd

Simplest is by adding docker argument: --device /dev/snd. Try via:

$ docker run --rm \
    --user root --device /dev/snd \
    wernight/mopidy \
    gst-launch-1.0 audiotestsrc ! audioresample ! autoaudiosink

PulseAudio native

Mount the current user's pulse directory to the pulseuadio user (UID 105). Based on https://github.com/TheBiggerGuy/docker-pulseaudio-example.

$ docker run --rm \
    --user $UID:$GID -v /run/user/$UID/pulse:/run/user/105/pulse \
    wernight/mopidy \
    gst-launch-1.0 audiotestsrc ! audioresample ! autoaudiosink

PulseAudio over network

First to make audio work from within a Docker container, you should enable PulseAudio over network; so if you have X11 you may for example do:

  1. Install PulseAudio Preferences. 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
    

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.

Now set the environment variables:

  • PULSE_SERVER - PulseAudio server socket.
  • PULSE_COOKIE_DATA - Hexadecimal encoded PulseAudio cookie commonly at ~/.config/pulse/cookie.

Example to check it works:

$ docker run --rm \
    -e "PULSE_SERVER=tcp:$(hostname -i):4713" \
    -e "PULSE_COOKIE_DATA=$(pax11publish -d | grep --color=never -Po '(?<=^Cookie: ).*')" \
    wernight/mopidy \
    gst-launch-1.0 audiotestsrc ! audioresample ! autoaudiosink

General usage

$ docker run -d \
    $PUT_HERE_EXRA_DOCKER_ARGUMENTS_FOR_AUDIO_TO_WORK \
    -v "$PWD/media:/var/lib/mopidy/media:ro" \
    -v "$PWD/local:/var/lib/mopidy/local" \
    -p 6600:6600 -p 6680:6680 \
    --user $UID:$GID \
    wernight/mopidy \
    mopidy \
    -o spotify/username=USERNAME -o spotify/password=PASSWORD \
    -o gmusic/username=USERNAME -o gmusic/password=PASSWORD \
    -o soundcloud/auth_token=TOKEN

Most arguments are optional (see some examples below):

  • Docker arguments:
    • $PUT_HERE_EXRA_DOCKER_ARGUMENTS_FOR_AUDIO_TO_WORK should be replaced with some arguments that work to play audio from within the docker container as tested above.
    • -v ...:/var/lib/mopidy/media:ro - (optional) Path to directory with local media files.
    • -v ...:/var/lib/mopidy/local - (optional) Path to directory to store local metadata such as libraries and playlists in.
    • -p 6600:6600 - (optional) Exposes MPD server (if you use for example ncmpcpp client).
    • -p 6680:6680 - (optional) Exposes HTTP server (if you use your browser as client).
    • -p 5555:5555/udp - (optional) Exposes UDP streaming for FIFE sink (e.g. for visualizers).
    • --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). 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. Similar for other mounts. If you have issues, try first as --user root.
  • Mopidy arguments (see mopidy's command for possible additional options), replace USERNAME, PASSWORD, TOKEN accordingly if needed, or disable services (e.g., -o spotify/enabled=false):
    • For Spotify you'll need a Premium account.
    • For Google Music use your Google account (if you have 2-Step Authentication, generate an app specific password).
    • For SoundCloud, just get a token after registering.

NOTE: Any user on your system may run ps aux and see the command-line you're running, so your passwords may be exposed. A safer option if it's a concern, is using putting these passwords in a Mopidy configuration file based on mopidy.conf:

[core]
data_dir = /var/lib/mopidy

[local]
media_dir = /var/lib/mopidy/media

[audio]
output = tee name=t ! queue ! autoaudiosink t. ! queue ! udpsink host=0.0.0.0 port=5555

[m3u]
playlists_dir = /var/lib/mopidy/playlists

[http]
hostname = 0.0.0.0

[mpd]
hostname = 0.0.0.0

[spotify]
username=USERNAME
password=PASSWORD

[gmusic]
username=USERNAME
password=PASSWORD

[soundcloud]
auth_token=TOKEN

Then run it:

$ docker run -d \
    $PUT_HERE_EXRA_DOCKER_ARGUMENTS_FOR_AUDIO_TO_WORK \
    -v "$PWD/media:/var/lib/mopidy/media:ro" \
    -v "$PWD/local:/var/lib/mopidy/local" \
    -v "$PWD/mopidy.conf:/config/mopidy.conf" \
    -p 6600:6600 -p 6680:6680 \
    --user $UID:$GID \
    wernight/mopidy
Example using HTTP client to stream local files
  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).

  2. Index local files:

    $ docker run --rm \
        --device /dev/snd \
        -v "$PWD/media:/var/lib/mopidy/media:ro" \
        -v "$PWD/local:/var/lib/mopidy/local" \
        -p 6680:6680 \
        wernight/mopidy mopidy local scan
    
  3. Start the server:

    $ docker run -d \
        -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 6680:6680 \
        wernight/mopidy
    
  4. Browse to http://localhost:6680/

Example using ncmpcpp MPD console client

$ docker run --name mopidy -d \
    -v /run/user/$UID/pulse:/run/user/105/pulse \
    wernight/mopidy
$ docker run --rm -it --net container:mopidy wernight/ncmpcpp ncmpcpp

Alternatively if you don't need visualizers you can do:

$ docker run --rm -it --link mopidy:mopidy wernight/ncmpcpp ncmpcpp --host mopidy

Feedbacks

Having more issues? Report a bug on GitHub. Also if you need some additional extensions/plugins that aren't already installed (please explain why).

Alsa Audio

For non debian distros. The gid for audio group in /etc/group must be 29 to match debians default as audio:x:29:<your user outside of docker> this is to match the user id inside the docker container. You'll also need to add the output = alsasink config line under the audio section in your mopidy.conf.

$ docker run -d -rm \
  --device /dev/snd \
  --name mopidy \
  --ipc=host \
  --privileged \
  -v $HOME/.config/mopidy:/var/lib/mopidy/.config/mopidy/ \
  -p 6600:6600/tcp -p 6680:6680/tcp -p 5555:5555/udp \
  mopidy

More Repositories

1

docker-ngrok

An Ngrok v2 container based on wizardapps/ngrok and fnichol/ngrok
Shell
451
star
2

powerline-web-fonts

Powerline Web Fonts for Chromebook
HTML
207
star
3

docker-funbox

Docker container with fun terminal commands and ASCII art.
Shell
140
star
4

docker-dante

Dante SOCKS proxy server
Dockerfile
129
star
5

docker-plex-media-server

Dockerized Plex Media Server
Shell
127
star
6

renameit

Rename-It! is a Windows software to safely rename of thousands of files and folders at once via regex and all kind of other renaming filters. See the wiki section for more details.
C++
104
star
7

docker-youtube-dl

Dockerized youtube-dl based on Alpine Linux.
Dockerfile
80
star
8

docker-kubectl

Containerized Kubernetes kubectl
54
star
9

scruffy-server

Scruffy micro web server to have your own UML class/sequence diagram page like yUML and even more lean.
Smarty
44
star
10

docker-duplicity

Dockerize "duplicity" backup tool.
Dockerfile
36
star
11

docker-alpine-nginx-pagespeed

Dockerized Nginx with PageSpeed Module on Alpine Linux
29
star
12

docker-cpuminer-multi

Dockerized cpuminer-multi a multiple crypto currency miner.
Dockerfile
28
star
13

kubernetes-che

Example deploying Eclipse Che on a Kubernetes cluster
20
star
14

docker-compose

Minimal docker-compose based on Alpine Linux.
Dockerfile
19
star
15

docker-bfgminer

Dockerized BFGMiner
9
star
16

docker-squid

Dockerized Squid forward proxy
8
star
17

docker-trafficserver

Dockerized Apache Traffic Server
7
star
18

docker-kubernetes-dind

Kubernetes and Docker Registry in a Docker-in-Docker
Shell
6
star
19

gerrit-hooks-examples

Gerrit Hooks Examples
Python
5
star
20

docker-mitmproxy

Containerized mitmproxy (man-in-the-middle proxy) on top of Alpine Linux.
4
star
21

docker-sikulix

Dockerized SikuliX
4
star
22

docker-spdyproxy

Dockerized SPDY forwarding proxy.
Shell
3
star
23

mountnfall

Simple board game written in Java.
Java
2
star
24

vs-project-dependency-graph

Visual Studio 2008, 2010 and 2012 project dependencies visualization and graph.
C#
2
star
25

reverse-proxy

Setups virtual host reverse proxies on a Linux machine without root (good for Docker).
Shell
2
star
26

docker-ncmpcpp

Containerized ncmpcpp (MPC console client).
Dockerfile
1
star
27

glpong

Simple OpenGL game inspired by the classic pong.
C
1
star
28

git-example-hooks

Example Git hooks doing mostly Push-to-Deploy.
Python
1
star
29

bigle3d

Stereogram generator, a Windows application in C++
C++
1
star