I am trying to develop software that record sound from mic input. And I am using Docker to develop and run in container, but from container I cannot access to mic device.
Environments:
- docker:26.0.0.0
- python:3.12.3
- sounddevice:0.4.6
- LinuxMint(HostOS)
and here’s my dockerfile and compose.yml
###
# Base
FROM python:3.12-slim as base
# Install dependencies
RUN apt-get update
&& apt-get install -y --no-install-recommends curl gcc g++ pkg-config libssl-dev libasound-dev portaudio19-dev pulseaudio socat alsa-utils
&& apt-get clean
&& rm -rf /var/lib/apt/lists/*
# Create a app user and working directory
ENV APP_HOME=/app
RUN useradd -ms /bin/bash app
&& mkdir -p $APP_HOME
&& chown -R app:app $APP_HOME
# Switch to the app user and working directory
USER app
WORKDIR $APP_HOME
# Copy the requirements file
COPY --chown=app:app requirements.txt .
RUN pip install --no-cache-dir --upgrade -r requirements.txt
COPY --chown=app:app . .
services:
app:
build:
context: .
target: base
command: python3 -u -m observer
volumes:
- ./:/app
- ~/.config/pulse:/root/.config/pulse
devices:
- "/dev/snd:/dev/snd"
I tried to add -device:/dev/snd:/dev/snd but it did not work for me.