0

I have a docker container running on a raspberry pi 5 and my goal is to access the alsa audio devices of the raspy inside of the container.

Currently I get the following error when executing

aplay someaudio.wav

aplay: main:831: audio open error: Unknown error 524

Outside of the container audio is working

My dockerfile looks like this:

FROM python:3.12.4-slim-bookworm

ARG TARGETARCH

RUN apt update && apt upgrade -y && \
apt install -y wget gcc swig libmariadb-dev libasound2-dev alsa-utils

RUN if [ "$TARGETARCH" == "armhf" ]; then\
apt install build-essentials cmake -y ; \
else \
    apt install build-essential -y ; \
fi

COPY src/app /app

RUN pip install -r /app/requirements.txt

WORKDIR /app
ENTRYPOINT [ "uvicorn", "app:app", "--port", "8000", "--host", "0.0.0.0" ]

and this is the docker-compose

backend:
    image: pythonbasedimage
    volumes:
      - ${PWD}/.env:/app/.env
    devices:
      - "/dev/snd:/dev/snd"
    privileged: true
    ports:
      - "8000:8000"
    deploy:
      resources:
        limits:
          cpus: "0.5"

alsactl info shows the following:

#
# Sound card
#
- card: 0
  id: vc4hdmi0
  name: vc4-hdmi-0
  longname: vc4-hdmi-0
  driver_name: vc4-hdmi
  mixer_name:
  components:
  controls_count: 5
  pcm:
    - stream: PLAYBACK
      devices:
        - device: 0
          id: MAI PCM i2s-hifi-0
          name: MAI PCM i2s-hifi-0
          subdevices:
            - subdevice: 0
              name: subdevice #0
alsactl: rawmidi_device_list:105: snd_ctl_rawmidi_next_device
3
  • Is someaudio.wav file accessible from within the container via some volume mapping? Have you tried to search for the error code Unknown error 524? Commented Aug 15 at 12:33
  • yes the audiofile is accessible inside the container (uploaded via a frontend). Yes I've been googling and "AI-ing" a lot but didn't find a solution
    – swissmount
    Commented Aug 15 at 12:37
  • Ok, my initial guess would be that maybe there are some dependencies missing. You could check by creating a Dockerfile where you copy a .wav file into the container and directly execute aplay someaudio.wav as the ENTRYPOINT to see if that works with the current dependencies and maybe add more (or change base image) to see if that solves the issue. Commented Aug 15 at 12:43

1 Answer 1

0

I was able to fix it using pipewire, as described in this stackoverflow answer: Answer

My changes to the Dockerfile were:

RUN apt update && apt upgrade -y && \
apt install -y wget gcc swig libmariadb-dev pipewire-alsa pipewire libasound2-dev alsa-utils

and in the docker compose I changed the following:

backend:
    image: someimage
    depends_on:
      - db
      - asterisk
    volumes:
      - ${PWD}/.env:/app/.env
      - /run/user/1000/pipewire-0:/tmp/pipewire-0
    environment:
      - XDG_RUNTIME_DIR=/tmp
    privileged: true
    ports:
      - "8000:8000"
    deploy:
      resources:
        limits:
          cpus: "0.5"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.