[Guide] Running gnuradio-companion using librespace/gnuradio docker images (wayland)

Hello everyone,

After being in contact with Nestoras, I was asked to contribute to the forum so others can learn from the shared knowledge gained.

I have been trying to get gnuradio-companion working from within docker, primarily because I found manual installation of a compiled from source version together with several Oot-Of-Tree (OOT) modules cumbersome and sometimes tricky. Many of these compilation complexities stem from non-standard import paths for headers, libraries, cmake and pkg-config configuration files. While I am sure there are ways to make it work with Conda or Spack etc I found that just installing everything in docker can be very convenient. With this lengthy introduction out of the way, the actual steps are pretty straightforward. These shown steps are specifically for Wayland in this case.

docker run -it \
-e XDG_RUNTIME_DIR=/tmp \
-e WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
-e QT_QPA_PLATFORM=wayland \
-v $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/tmp/$WAYLAND_DISPLAY \
librespace/gnuradio /bin/bash

Then simply install dbus and gtk:

apt update
apt install dbus-x11 gir1.2-gtk-3.0

You can now start gnuradio-companion

gnuradio-companion

Some limitations, GPU acceleration and audio won’t work as of yet in this container.
I tried getting pulseaudio working by adding the follow parameters to ‘docker run’.

--device /dev/dri
–device /dev/snd
-e PULSE_SERVER=unix:/run/user/$(id -u)/pulse/native
-v /run/user/$(id -u)/pulse/native:/run/user/root/pulse/native
-v ~/.config/pulse/cookie:/root/.config/pulse/cookie \

You need to install some additional packages using

apt install libpulse0 pulseaudio-utils alsaplayer-alsa alsa-utils

Unfortunately, gnuradio can’t seem to find the pulse devices, I think this is because we are only passing pulseaudio to the container not alsa. And as far as I know Gnuradio uses alsa to lookup the pulse / pipewire devices. So you get the error ‘unknown PCM alsa’. When you instead try to play a sound using the ‘aplay’ utility it works fine, so pulse is actually working in the container.

One last thing, you might notice everything runs as root in the container. This is because its quite some extra steps to get it working with your own userid inside the container. You need both a custom Dockerfile and an entrypoint I have includded them hidden below.

Dockerfile

ARG DEBIAN_IMAGE_TAG=librespace/gnuradio
FROM ${DEBIAN_IMAGE_TAG}

RUN apt update && apt install -y dbus-x11 gir1.2-gtk-3.0 libpulse0 pulseaudio-utils gosu alsaplayer-alsa alsa-utils

COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT [“/usr/local/bin/entrypoint.sh”]

CMD [“gnuradio-companion”]

Entrypoint.sh
#!/bin/bash

# Configuration
USER_ID=${USER_ID:-1000}
GROUP_ID=${GROUP_ID:-1000}
USER_NAME=${USER_NAME:-dockeruser}

echo "Configuring container for UID: $USER_ID and GID: $GROUP_ID..."

if ! getent group $GROUP_ID > /dev/null; then
    groupadd -g $GROUP_ID $USER_NAME
fi

if ! getent passwd $USER_ID > /dev/null; then
    useradd -u $USER_ID -g $GROUP_ID -m -s /bin/bash $USER_NAME
else
    # If user exists, ensure home dir
    USER_NAME=$(getent passwd $USER_ID | cut -d: -f1)
    mkdir -p /home/$USER_NAME
fi

# Set permissions
chown -R $USER_ID:$GROUP_ID /home/$USER_NAME

# Set pulseaudio cookie
mkdir -p /home/$USER_NAME/.config/pulse
chown -R $USER_ID:$GROUP_ID /home/$USER_NAME/.config/pulse

echo "Switching to user $USER_NAME..."

# Run application with gosu
exec gosu $USER_NAME "$@"
Extended docker run command (still no sound in gnuradio)

docker run -it \
–device /dev/dri \
–device /dev/snd \
-e USER_ID=$(id -u) \
-e GROUP_ID=$(id -g) \
-e XDG_RUNTIME_DIR=/tmp \
-e WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
-e QT_QPA_PLATFORM=wayland \
-e PULSE_SERVER=unix:/run/user/$(id -u)/pulse/native \
-v $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/tmp/$WAYLAND_DISPLAY \
-v /run/user/$(id -u)/pulse/native:/run/user/$(id -u)/pulse/native \
-v ~/.config/pulse/cookie:/home/dockeruser/.config/pulse/cookie \
librespace/gnuradio /bin/bash

I hope this is somehow vaguely interesting or useful to you. Took more time to put on paper then I thought.
Kind regards,
Corne (Dantali0n)

3 Likes

I managed to get sound working with pipewire by creating a little asound config:

pcm.!default {
    type plug
    slave.pcm "duplex"
    slave.rate 48000
}

pcm.duplex {
    type asym
    playback.pcm "dmix:CARD=0"
    capture.pcm  "dsnoop:CARD=0"
}

This asound config needs to be placed at /etc/asound.conf inside the container.

To pass along pipewire add the following to the run command:

docker run ... -v $XDG_RUNTIME_DIR/pipewire-0:/tmp/pipewire-0 -e PIPEWIRE_RUNTIME_DIR=tmp 

For this to work I had to drop the entrypoint.sh setup and run everything as root.