Giter Site home page Giter Site logo

Comments (21)

fsmunoz avatar fsmunoz commented on May 18, 2024 23

Just to add something since this is one of the top results and the most informative: after some testing and multiple approaches the following should work for those in a RHEL7 host (or similar) running Chrome or similar:

## Sound options for RHEL7 OpenClient
snd_opts="--device /dev/snd \
	-e PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native \
	-v ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native \
	--group-add $(getent group audio | cut -d: -f3)"

Note that this implies running pulseaudio on the host (which is the default). It also uses the default module-native-protocol-unixmodule instead of the TCP one (avoiding having to enable it just for this).

This works for me for the ones I've tried, based on Ubuntu and Debian; I suppose that the paths inside the container should be updated to reflect each distribution, I remember that dbus had different default locations some time ago.

from dockerfiles.

lidel avatar lidel commented on May 18, 2024 7

Bit late to the party, but if anyone still wants to get it working on desktop with PulseAudio:

  1. Add load-module module-native-protocol-tcp to /etc/pulse/default.pa & restart PA

  2. Make sure PulseAudio cookie is present in X11 root

    # Set up PulseAudio Cookie if missing
    if [ x"$(pax11publish -d)" = x ]; then
        start-pulseaudio-x11
    fi
  3. Pass PA address to the container as PULSE_SERVER (tcp:localhost:4713 is a default for module-native-protocol-tcp):

     -e PULSE_SERVER=tcp:localhost:4713
  4. Extract & pass PA cookie:

    -e PULSE_COOKIE_DATA=`pax11publish -d | grep --color=never -Po '(?<=^Cookie: ).*'` 

Personally, I use a wrapper script that takes care of 2-4.

from dockerfiles.

jessfraz avatar jessfraz commented on May 18, 2024 6

Or try --group-add audio on run

from dockerfiles.

atilaromero avatar atilaromero commented on May 18, 2024 5

to keep it short:
--group-add $(getent group audio | cut -d: -f3)

from dockerfiles.

pwFoo avatar pwFoo commented on May 18, 2024 3

I get sound working with chromium executed as a "normal" user (uid 1000).

  1. Maybe you need dbus and shm inside the container
-v /run/dbus/:/run/dbus/ -v /dev/shm:/dev/shm
  1. The user have to be member of the audio group inside the container (isn't needed outside...)

  2. audio group gid have to be the same inside and outside the container (something like "groupmod --gid $AUDIO_GID audio" inside...)

Maybe not all is necessary, but I need all together to get it work...

docker run --rm --name chromium --device /dev/snd -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v /run/dbus/:/run/dbus/:rw -v /dev/shm:/dev/shm <myCustomChromiumImage>

But success is also docker host dependent (arch missing USER_NS, alpine fails because of security features like grsec I think,...). All works fine with Voidlinux for me...

from dockerfiles.

aroman avatar aroman commented on May 18, 2024 3

Just for any future travelers finding this bug: if you are trying to play audio via ALSA (without PulseAudio), and find that dockerized Chromium does not respect which output device you're using in the host, you can force Chromium to use a particular ALSA device via: this command line flag: --alsa-output-device=hw:0,3.

(Replace 0 and 3 with whatever your actual output device location is)

from dockerfiles.

ssebastianj avatar ssebastianj commented on May 18, 2024 1

@lidel: Nice, that solution gave my containers the power of sound 😄

Tested on:

from dockerfiles.

jessfraz avatar jessfraz commented on May 18, 2024

The problem is probably pulseaudio on your host interfering 

from dockerfiles.

jessfraz avatar jessfraz commented on May 18, 2024

I would look at the other issues in this repo wrt to sound and see if any of them fix it

from dockerfiles.

pwFoo avatar pwFoo commented on May 18, 2024

Will it map the hosts group or just add the user to the group existing inside the container?
If host (Voidlinux) and container (Debian) are different also the gid could be different.

void

audio:x:12:pulse

debian

audio:x:29:

from dockerfiles.

mosajjal avatar mosajjal commented on May 18, 2024

my problem with sound in Chrome is, when I play a sound (e.g. music) on my host, Chrome's sound is off and vice versa. I couldn't make them both have sound at the same time.

from dockerfiles.

briceburg avatar briceburg commented on May 18, 2024

jess/chrome is built on debian:sid, and the gid mappings may not line up with the host (e.g. on archlinux the audio group is 91, on debian it's 29). @pwFoo brought this up above.

I use a wrapper script with something like:

for group in audio video; do
  gid=$(getent group $group | cut -d: -f3)
  [ -z "$gid" ] || __docker_flags+=" --group-add=$gid"
done

Visiting http://hpr.dogphilosophy.net/test/ should help test. Beware around 2:35 in the first audio clip, things get CRAZY!

I'm attempting to use this technique in dex -- in the v1 runtime here -- which is working well for the chrome image based on jess's work.

from dockerfiles.

denysvitali avatar denysvitali commented on May 18, 2024

@atilaromero solution worked for me!

from dockerfiles.

guiambros avatar guiambros commented on May 18, 2024

Thanks @fsmunoz! Much appreciated.

This worked for me, host on ubuntu 14.04 using Pulse Audio.

from dockerfiles.

dadreggors avatar dadreggors commented on May 18, 2024

@fsmunoz I got jess/spotify audo working on Fedora 26 by adding this to end of run command but you seem to be adding this to a script or env file to set a variable. Where would you add that variable definition and how would you use this variable to start docker containers needing audo support?

Sorry, new to docker

from dockerfiles.

fsmunoz avatar fsmunoz commented on May 18, 2024

@ddreggors take a look at https://gist.github.com/fsmunoz/d83dbcf6c60b651491e0815b12158d1c , this is how I do it. IIRC @jessfraz does something similar but at this stage I'm not sure exactly from whom I stole it, the idea is that I have dockerised applications as alias so I can launch them "normally". Some settings there could be over the top in terms of limiting access but my own usage is more about convenience.YMMV, and hope this helps.

from dockerfiles.

dadreggors avatar dadreggors commented on May 18, 2024

@fsmunoz that file name is good, and the contents are helpful too, however I still do not know where it is placed or how it is used. Does docker automatically source this file in like /etc/sysconfig/docker or is that sourced in via a wrapper script? If it is a wrapper script can you elaborate some on how it is used/sourced?

from dockerfiles.

fsmunoz avatar fsmunoz commented on May 18, 2024

@ddreggors oh, right. No, this is my ~/.alias file which I source from my ~/.bashrc by adding . ~/.alias to it. It is then usable in all terminals. Something similar can be done to add them to menus but since I don't use them (apart from wmii menu or i9 menu)I never felt the need.

from dockerfiles.

dadreggors avatar dadreggors commented on May 18, 2024

ahh that was the missing piece, I was failing to see how that was used. Thanks for the explanation @fsmunoz I appreciate it!

from dockerfiles.

jhf2442 avatar jhf2442 commented on May 18, 2024

Solved on arch linux by rebuilding the docker file, adding mapping to the GIDs audio and video as they differ between debian an arch linux, in order to have correct GID on /dev/snd/*
RUN groupmod -g 92 audio
RUN groupmod -g 91 video

from dockerfiles.

jessfraz avatar jessfraz commented on May 18, 2024

this should be fixed or working now but let me know if otherwise

from dockerfiles.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.