Some tips on Snapcast and Mopidy with Pipewire on Docker

I’ve recently implemented a whole home audio stack on Docker. The stack works with Pipewire on Debian but not without some work. Here are some tips I’ve found:


Snapclient

Check out this StackOverflow answer to get Pipewire working in Docker. You need to install pipewire in the Dockerfile so that it contains the client-side lib.

Another tip is to run snapclient with the --soundcard pipewire flag. With this, Snapclient would appear as an audio application in the host’s mixer instead of hogging the host’s audio. You can run multiple instance of snapclient too!

FROM debian:stable-slim

ENV HOST snapserver
ENV SOUNDCARD pipewire
ENV PORT 1704

RUN set -eux ; \
    apt-get update ; \
    apt-get install -y --no-install-recommends \
        snapclient \
        pipewire-audio wireplumber \
        pipewire-media-session- \
    ; \
    rm -rf /var/lib/apt/lists/* ;

ENTRYPOINT /usr/bin/snapclient -h $HOST -p $PORT --soundcard $SOUNDCARD

In your compose, you need the following to get Pipewire working:

    cap_add:
      - SYS_NICE
    environment:
      - XDG_RUNTIME_DIR=/tmp
    volumes:
      - /run/user/1000/pipewire-0:/tmp/pipewire-0
      - /run/dbus/system_bus_socket:/run/dbus/system_bus_socket
    devices:
      - "/dev/snd:/dev/snd"

Snapserver

The image ivdata/snapserver works flawlessly. The snapserver.conf is just:

[stream]
stream = pipe:///tmp/snapfifo?name=mopidy

In the compose, I put the tmp directory as a volume instead of bind mount. This is to avoid Mopidy’s permission error. You don’t need to mkfifo before running.

    volumes:
      - tmp:/tmp
volumes:
  tmp:

Mopidy

I used a custom version of firefrei/docker-mopidy. However, I encountered permission errors. The issue is that Mopidy needs to be run as a system user mopidy:audio. Because I don’t use Mopidy with local files, my workaround is just to chmod 777 the Mopidy directory.

Again, put the tmp directory as a volume. Here’s an extract of the mopidy.conf:


[core]
data_dir = /var/lib/mopidy
cache_dir = /tmp/mopidy
#config_dir = $XDG_CONFIG_DIR/mopidy
#data_dir = $XDG_DATA_DIR/mopidy
#max_tracklist_length = 10000
#restore_state = false

[audio]
output = audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! wavenc ! filesink location=/tmp/snapfifo

[softwaremixer]

[http]
enabled = true
hostname = ::
port = 6680

[mpd]
enabled = true
hostname = 0.0.0.0
port = 6600

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.