USB Microphone Detected on Host but Not Recognized Inside Docker Container on Verdin i.MX8M Plus (Torizon OS)

Hi,

I am using a USB PnP microphone (C-Media 08bb:2902) on a Verdin i.MX8M Plus running Torizon OS.
The mic is visible on the host system but ALSA and PulseAudio inside our container cannot detect it even after mapping /dev/snd and /proc/asound.
We need guidance on the correct way to access USB sound devices from within containers in Torizon OS (direct ALSA vs PulseAudio socket).

torizon@verdin-imx8mp-15502128:~$ cat /proc/asound/cards
0 [Device ]: USB-Audio - USB PnP Sound Device
C-Media Electronics Inc. USB PnP Sound Device at usb-xhci-hcd.1.auto-1.2, full
1 [audiohdmi ]: audio-hdmi - audio-hdmi
audio-hdmi
torizon@verdin-imx8mp-15502128:~$ cat /proc/asound/pcm
00-00: USB Audio : USB Audio : capture 1
01-00: i.MX HDMI i2s-hifi-0 : i.MX HDMI i2s-hifi-0 : playback 1
torizon@verdin-imx8mp-15502128:~$ cat /proc/asound/devices
2: [ 0- 0]: digital audio capture
3: [ 0] : control
4: [ 1- 0]: digital audio playback
5: [ 1] : control
33: : timer
torizon@verdin-imx8mp-15502128:~$

Regards,
Anurag

Hi, I’m the Toradex AI Assistant.

I might make mistakes or occasionally get you wrong. Our support team will step in if needed.


Hello Anurag,

I understand you’re having trouble accessing a USB PnP microphone from within a container on your Verdin iMX8M Plus running Torizon OS. Let me provide guidance on the correct container setup for USB audio devices.

Container Configuration for USB Audio Devices

For audio devices in Torizon OS containers, you need to ensure proper device access. The standard approach is to mount the /dev directory and provide access to all audio devices(1):

docker run -it --rm -v /dev:/dev --device-cgroup-rule='c 89:* rmw' <container_namespace>

(1)

This command gives the container access to all I2C buses with the --device_cgroup_rules flag, but the same principle applies to audio devices(1).

Recommended Audio Setup in Torizon Containers

Direct ALSA Access (Recommended)

The recommended approach for audio in Torizon containers is direct ALSA usage(2). Here’s the minimal setup:

  1. Expose /dev/snd devices:
docker run -it --rm --device /dev/snd <your-container>

(2)

  1. Verify device detection:
    Inside your container, check if your USB microphone is detected:
aplay -l
cat /proc/asound/cards

(2)

Why PulseAudio Isn’t Recommended

PulseAudio and PipeWire aren’t enabled or recommended in standard Torizon images(2). They require additional configuration to run properly in containers due to user session management, permissions, and shared resources, which adds complexity and overhead contrary to Torizon design principles(2).

Troubleshooting USB Audio Detection

If your USB microphone still isn’t detected after mounting /dev/snd, try these steps:

  1. Check if the device appears on the host:
lsusb
dmesg | grep -i audio
  1. Use software mixing for better compatibility:
    For recording or playback that requires software mixing, use the plug:dmix ALSA device(2):
arecord -D plug:dmix -f cd test.wav
  1. Alternative device access method:
    You can also mount the entire /dev directory with device cgroup rules(1):
docker run -it --rm -v /dev:/dev --device-cgroup-rule='c 89:* rmw' <container_namespace>

Container Run Command Example

Here’s a complete example for running a container with USB audio support:

docker run -it --rm \
  --device /dev/snd \
  -v /tmp:/tmp \
  -v /var/run/dbus:/var/run/dbus \
  --security-opt seccomp=unconfined \
  <your-container-image>

(2)

This setup should allow your C-Media USB microphone to be accessible via ALSA within your container.

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

Hi,

What’s the output from within the container, regarding the snd devices?
As well as “aplay -L”?

Personally, I decided to go back to the OpenEmbedded build process, because I can’t figure out how to properly share /proc. However I was able to get audio recording and playback working with arecord and aplay even within a container.

Hi,
Here are the outputs when running the commands:
ls -l /dev/snd
by-id by-path controlC0 controlC1 pcmC0D0c pcmC1D0p timer

aplay -L
null
Discard all samples (playback) or generate zero samples (capture)

arecord -L
null
Discard all samples (playback) or generate zero samples (capture)

Regards,
Anurag

Hey @AnuragBluAI,

Can you share the docker run command you are using to launch your container?

-Eric

Hi @eric.tx ,
Here’s the docker run command equivalent to how I’m currently launching my container (torizon-vitaldata-debug-1):

docker run -d --name torizon-vitaldata-debug-1
–restart=always
–privileged
–ipc=host
-p 2222:2222
-p 5001:5000
-v /dev:/dev
-v /mnt/shared_ipc:/mnt/shared_ipc
-v /proc/asound:/proc/asound:ro
-v /usr/share/alsa:/usr/share/alsa:ro
-v $(pwd)/audio:/app/audio
–device=/dev/verdin-uart1:/dev/verdin-uart1
–device=/dev/verdin-uart2:/dev/verdin-uart2
–device=/dev/snd
192.168.8.155:5002/vitaldata-debug:arm64
/usr/sbin/sshd -D

This includes:

  • --privileged to ensure full device access

  • All audio- and UART-related device bindings

  • Proper ALSA volume mounts (/proc/asound, /usr/share/alsa)

  • Port mappings for SSH debugging and TCP server

Regards,
Anurag

Hey @AnuragBluAI,

Is it possible you are connecting/disconnecting the usb device? You may need to configure a bind propagation.

-Eric

Hi @AnuragBluAI ,

Just checking if this helped any.

Best regards,

Hello @michael.tx ,

Yes, everything is working now.

After a few updates, I confirmed the issue was related to the debug mode container.
During quick testing, I used a temporary test container and the microphone worked correctly.
The problem turned out to be that my Dockerfile.debug was missing the required ALSA packages.

Adding the following line fixed it:

RUN apt-get -q -y update &&
apt-get -q -y install
libgpiod-dev:arm64
alsa-utils
libasound2
libasound2-plugins &&
apt-get clean && apt-get autoremove -y &&
rm -rf /var/lib/apt/lists/*

After rebuilding the container with this change,
the USB microphone was detected and audio recording worked properly inside the container.

Best,
Anurag