Creating a SqueezeboxServer container

For years I’ve been using a Logitech Squeezebox as my music system. First with the server software (slimserver) running on a Linux Box and later-on on a Synology NAS device.

As Synology stopped supporting the SqueezeboxServer it’s time to move the software into a Docker container. This way I’m able to use everything the way I used to and move the software towards another server (or run it at the Synology box via Docker).

As I want to use a very specific version of the SqueezeboxServer software I’m not using the Docker image the current developers of the software have created (see the references). I decided to created my own docker-compose + Dockerfile combination. This article describes those.

Dockerfile (Building the image)

As a start I choose a Docker image of perl on which I set the locale and some environment variables to allow CPAN “do it’s job” without asking for input.

FROM perl:5.22-threaded as build

ENV PERL_MM_USE_DEFAULT=1
ENV PERL_MM_NONINTERACTIVE=1
ENV AUTOMATED_TESTING=1
ENV LANG=C.UTF-8

After this step I copy in the archive containing the source of the version I wanted to use (7.9.1) plus a little shell script which will make sure the environment of the container is set-up before slimserver starts.

COPY logitechmediaserver-7.9.1.tgz /
COPY entrypoint.sh /

Next step is extracting the archive, creating a user and making sure the rights are set correctly. Also the SSL Library from CPAN is installed.

RUN mkdir /opt/SqueezeboxServer  &&\
    useradd squeezeboxserver  &&\
    ln -f  /usr/local/bin/perl /usr/bin/perl  &&\
    tar -xzf /logitechmediaserver-7.9.1.tgz -C /opt/SqueezeboxServer  &&\
    chown -R squeezeboxserver /opt/SqueezeboxServer  &&\
    ln -s /opt/SqueezeboxServer/logitechmediaserver-7.9.1 /opt/sbs &&\
    cpan IO::Socket::SSL &&\
    chmod 755 /entrypoint.sh

Next up, telling Docker the image exposes some ports

expose 3483/tcp
expose 3483/udp
expose 9090/tcp
expose 9000/tcp

And finally setting environment variables necessary to run the slimserver and entrypoint script

ENV PERL5LIB="/opt/sbs/CPAN"
ENV RUNUSER=squeezeboxserver

WORKDIR /

ENTRYPOINT ["/entrypoint.sh", "/usr/bin/perl /opt/sbs/slimserver.pl"]

The entrypoint script itself is quite simple as well. It makes sure the access rights are correct in the folders the container is going to use and starts slimserver as the user we created for it.

#!/bin/bash
# 
#

echo Make sure the rights are set properly....

for folder in Logs prefs Cache; do
  echo -n updating $folder.....
  chown -R ${RUNUSER} /opt/sbs/${folder}
  echo done.
done

cd /
exec su -p ${RUNUSER} -c "$@"

Next up is the docker-compose.yml which launches the container and pieces everything together.

docker-compose.yml (Piecing all together)

The docker-compose.yml is very simple as well. It tells Docker to build the image if it’s not there yet and to launch it. It also attaches a few volumes to the container, so things like preferences and settings become persistent.

version: '2'
services:
    squeezeboxserver:
        build: build
        container_name: sbs
        network_mode: host
        restart: always
        volumes:
          - /opt/DockerData/General/SqueezeboxServer/prefs:/opt/sbs/prefs
          - /opt/DockerData/General/SqueezeboxServer/cache:/opt/sbs/Cache
          - /opt/DockerData/General/SqueezeboxServer/logs:/opt/sbs/Logs
          - /opt/DockerData/General/SqueezeboxServer/music:/opt/music
          - /opt/DockerData/General/SqueezeboxServer/playlist:/opt/playlist

One special thing in the set-up is the network attachment of the container. I attach it to the interface of the Docker host instead of creating a private network. Reason for this is the fact the slimserver announces the ip-address to the clients. If it is running within a private network the clients won’t be able to connect. I also have plugins which need to be attached to the “real network” to function properly.

Files

You can download the files I’ve used if you like. The zip-file does not contain the sources for the slimserver itself. To download those, use the link in the references.

References