Docker container audio output to Libreelec

  • Is it possible for Docker containers to output audio to alsa on Libreelec? I have done a lot of searching and have not seen this question answered directly, but indirectly I see indications that yes it can and no it can't.

    If it can is there some kind of reference container that shows the proof of concept?

    Is there a work around using pulse audio or some other means?

    Thanks all.

  • Go back to studying the documentation about docker, the --privileged parameter allows access to the hardware and therefore the audio output

    Thank you for the reply.

    The rest of this post basically answers my original question since today I was able to have success with speaker-test in a container and could hear it from the receiver.

    I had found --privileged and used it in prior attempts. It does permit the listing of /proc/asound, but I could not get beyond that.

    ls -al /proc/asound

    LibreELECWyse:~ # aplay -L

    null

    Discard all samples (playback) or generate zero samples (capture)

    hdmi:CARD=HDMI,DEV=0

    HDA ATI HDMI, HDMI 0

    HDMI Audio Output

    hdmi:CARD=HDMI,DEV=1

    HDA ATI HDMI, HDMI 1

    HDMI Audio Output

    sysdefault:CARD=Generic

    HD-Audio Generic, ALC231 Analog

    Default Audio Device

    front:CARD=Generic,DEV=0

    HD-Audio Generic, ALC231 Analog

    Front output / input

    surround21:CARD=Generic,DEV=0

    HD-Audio Generic, ALC231 Analog

    2.1 Surround output to Front and Subwoofer speakers

    surround40:CARD=Generic,DEV=0

    HD-Audio Generic, ALC231 Analog

    4.0 Surround output to Front and Rear speakers

    surround41:CARD=Generic,DEV=0

    I made a docker container to run speaker-test and did get sound output. Dockerfile:

    FROM alpine:3.12

    RUN apk --no-cache add alsa-utils

    CMD [ "sh" ]

    LibreELECWyse:~ # docker run --rm --privileged --device /dev/snd aucdb speaker-test -D hdmi:CARD=HDMI,DEV=0 -c 2 -b544000

    speaker-test 1.2.2

    Playback device is hdmi:CARD=HDMI,DEV=0

    Stream parameters are 48000Hz, S16_LE, 2 channels

    Using 16 octaves of pink noise

    Rate set to 48000Hz (requested 48000Hz)

    Buffer size range from 64 to 8544000

    Period size range from 32 to 4272000

    Requested buffer time 544000 us

    Periods = 4

    was set period_size = 6528

    was set buffer_size = 26112

    0 - Front Left

    1 - Front Right

    Time per period = 5.453585

    0 - Front Left

    ...

    Thanks to all.

    Edited 2 times, last by Cfan: spelling (August 3, 2021 at 2:04 AM).

  • Now I know that speaker-test works from Docker on Libreelec, I was hoping to get some help getting the shairport-sync-docker container running. I can run it just fine on Debian so I know it works.

    I have been working with the author trying get his container to run on Libreelec but have not had any success and just get these errors in the container log. Many combinations have been tried. I think it comes down to linux security and device access.

    If anybody has any suggestions things to try differently in the Dockerfile or the Entrypoint start.sh, it would be greatly appreciated.

    LibreELECWyse:~ # aplay -l

    **** List of PLAYBACK Hardware Devices ****

    card 0: HDMI [HDA ATI HDMI], device 3: HDMI 0 [HDMI 0]

    Subdevices: 1/1

    Subdevice #0: subdevice #0

    card 0: HDMI [HDA ATI HDMI], device 7: HDMI 1 [HDMI 1]

    Subdevices: 1/1

    Subdevice #0: subdevice #0

    card 1: Generic [HD-Audio Generic], device 0: ALC231 Analog [ALC231 Analog]

    Subdevices: 1/1

    Subdevice #0: subdevice #0

    docker run -d --rm --restart unless-stopped --privileged --net host --device /dev/snd mikebrady/shairport-sync -a DenSystem -- -d hw:0

    docker run -d --rm --restart unless-stopped --privileged --net host --device /dev/snd mikebrady/shairport-sync -a DenSystem -- -d hw:0,3


    ALSA lib pcm_hw.c:1829:(_snd_pcm_hw_open) Invalid value for card,

    ALSA lib pcm_hw.c:1829:(_snd_pcm_hw_open) Invalid value for card,


    From GitHub - mikebrady/shairport-sync-docker: Docker setup for Shairport Sync

    Dockerfile for shairport-sync

    FROM alpine:3.12 AS builder-base

    # General Build System:

    RUN apk -U add \

    git \

    build-base \

    autoconf \

    automake \

    libtool \

    dbus \

    su-exec \

    alsa-lib-dev \

    libdaemon-dev \

    popt-dev \

    mbedtls-dev \

    soxr-dev \

    avahi-dev \

    libconfig-dev \

    libsndfile-dev \

    mosquitto-dev \

    xmltoman

    # ALAC Build System:

    FROM builder-base AS builder-alac

    RUN git clone GitHub - mikebrady/alac: Apple Lossless Codec and Utility with Autotools

    WORKDIR alac

    RUN autoreconf -fi

    RUN ./configure

    RUN make

    RUN make install

    # Shairport Sync Build System:

    FROM builder-base AS builder-sps

    # This may be modified by the Github Action Workflow.

    ARG SHAIRPORT_SYNC_BRANCH=master

    COPY --from=builder-alac /usr/local/lib/libalac.* /usr/local/lib/

    COPY --from=builder-alac /usr/local/lib/pkgconfig/alac.pc /usr/local/lib/pkgconfig/alac.pc

    COPY --from=builder-alac /usr/local/include /usr/local/include

    RUN git clone GitHub - mikebrady/shairport-sync: AirPlay audio player. Shairport Sync adds multi-room capability with Audio Synchronisation

    WORKDIR shairport-sync

    RUN git checkout "$SHAIRPORT_SYNC_BRANCH"

    RUN autoreconf -fi

    RUN ./configure \

    --with-alsa \

    --with-dummy \

    --with-pipe \

    --with-stdout \

    --with-avahi \

    --with-ssl=mbedtls \

    --with-soxr \

    --sysconfdir=/etc \

    --with-dbus-interface \

    --with-mpris-interface \

    --with-mqtt-client \

    --with-apple-alac \

    --with-convolution

    RUN make -j $(nproc)

    RUN make install

    # Shairport Sync Runtime System:

    FROM alpine:3.12

    RUN apk -U add \

    alsa-lib \

    dbus \

    popt \

    glib \

    mbedtls \

    soxr \

    avahi \

    libconfig \

    libsndfile \

    mosquitto-libs \

    su-exec \

    libgcc \

    libgc++

    RUN rm -rf /lib/apk/db/*

    COPY --from=builder-alac /usr/local/lib/libalac.* /usr/local/lib/

    COPY --from=builder-sps /etc/shairport-sync* /etc/

    COPY --from=builder-sps /etc/dbus-1/system.d/shairport-sync-dbus.conf /etc/dbus-1/system.d/

    COPY --from=builder-sps /etc/dbus-1/system.d/shairport-sync-mpris.conf /etc/dbus-1/system.d/

    COPY --from=builder-sps /usr/local/bin/shairport-sync /usr/local/bin/shairport-sync

    # Create non-root user for running the container -- running as the user 'shairport-sync' also allows

    # Shairport Sync to provide the D-Bus and MPRIS interfaces within the container

    RUN addgroup shairport-sync

    RUN adduser -D shairport-sync -G shairport-sync

    # Add the shairport-sync user to the pre-existing audio group, which has ID 29, for access to the ALSA stuff

    RUN addgroup -g 29 docker_audio && addgroup shairport-sync docker_audio

    COPY start.sh /

    ENTRYPOINT [ "/start.sh" ]

    /start.sh code listing:

  • I have resolved this issue. There were two issues preventing this from working. One was the container was configured to run as a non-root user in start.sh. The second is specifying the correct device name as the default would not work. There apparently is no hardware mixer or I could not find the correct configuration.

    #!/bin/sh

    #start.sh

    set -e

    rm -rf /var/run/dbus.pid

    #mkdir -p /var/run/dbus

    dbus-uuidgen --ensure

    dbus-daemon --system

    avahi-daemon --daemonize --no-chroot

    #su-exec shairport-sync shairport-sync $@ --Does not work

    #su-exec root shairport-sync $@ -- Works

    shairport-sync $@ # Works

    shairport-sync.conf:

    ...

    // Back End Settings

    // These are parameters for the "alsa" audio back end.

    // For this section to be operative, Shairport Sync must be built with the following configuration flag:

    // --with-alsa

    alsa =

    {

    output_device = "hdmi:CARD=HDMI,DEV=0"; // the name of the alsa output device. Use "shairport-sync -h" to discover the names of ALSA hardware devices. Use "alsamix>

    // mixer_control_name = "PCM"; // the name of the mixer to use to adjust output volume. If not specified, volume in adjusted in software.

    // mixer_device = "HDMI,DEV=0"; //

    ...

    Thanks to all who replied.