Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

No sound when running Chrome in Docker container on Ubuntu 14.04 #85

Closed
asemt opened this Issue Nov 28, 2015 · 21 comments

Comments

Projects
None yet
@asemt
Copy link

asemt commented Nov 28, 2015

Hi,

@jfrazelle:
first of all: Thank you very much for these Dockerfiles - they're fantastic! 馃憦

My problem is related to running the Chrome Docker container without having sound inside the container. I run the container with:

docker run -it \
            --rm \
            --net host \
            --cpuset-cpus 0 \
            --memory 512mb \
            -v /tmp/.X11-unix:/tmp/.X11-unix \
            --device /dev/snd \
            -e DISPLAY=unix$DISPLAY \
            --name chrome \
            my/jfrazelle_chrome:2015-11-28

I get following errors as soon as Chrome tries to access the sound device (browsing to youtube.com, for example):

ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
            ALSA lib conf.c:4260:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
            ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
            ALSA lib conf.c:4260:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
            ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
            ALSA lib conf.c:4260:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
            ALSA lib conf.c:4739:(snd_config_expand) Evaluate error: No such file or directory
            ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM default
            ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
            ALSA lib conf.c:4260:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
            ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
            ALSA lib conf.c:4260:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
            ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
            ALSA lib conf.c:4260:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
            ALSA lib conf.c:4739:(snd_config_expand) Evaluate error: No such file or directory
            ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM default

I run Docker v1.9.1 build a34a1d5 on Ubuntu 14.04.3 LTS.

Some more information gathered inside the Chrome container:

root@godock:/# cat /proc/asound/cards 
 1 [PCH            ]: HDA-Intel - HDA Intel PCH
                      HDA Intel PCH at 0xf7418000 irq 65
root@godock:/# cat /proc/asound/modules 
 1 snd_hda_intel
root@godock:/# cat /proc/asound/devices 
  1:        : sequencer
  2: [ 1- 0]: digital audio playback
  3: [ 1- 0]: digital audio capture
  4: [ 1- 0]: hardware dependent
  5: [ 1]   : control
 33:        : timer



Any help would be much appreciated.

Best,
Andreas

@jessfraz

This comment has been minimized.

Copy link
Owner

jessfraz commented Nov 29, 2015

The problem is probably pulseaudio on your host interfering聽

@jessfraz

This comment has been minimized.

Copy link
Owner

jessfraz commented Nov 29, 2015

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

@pwFoo

This comment has been minimized.

Copy link

pwFoo commented Dec 6, 2015

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...

@jessfraz

This comment has been minimized.

Copy link
Owner

jessfraz commented Dec 6, 2015

Or try --group-add audio on run

@pwFoo

This comment has been minimized.

Copy link

pwFoo commented Dec 6, 2015

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:
@lidel

This comment has been minimized.

Copy link

lidel commented Apr 16, 2016

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.

@mosajjal

This comment has been minimized.

Copy link
Contributor

mosajjal commented Jun 18, 2016

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.

@ssebastianj

This comment has been minimized.

Copy link

ssebastianj commented Jul 28, 2016

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

Tested on:

@briceburg

This comment has been minimized.

Copy link

briceburg commented Aug 23, 2016

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.

@atilaromero

This comment has been minimized.

Copy link

atilaromero commented Sep 18, 2016

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

@denysvitali

This comment has been minimized.

Copy link

denysvitali commented Nov 30, 2016

@atilaromero solution worked for me!

@fsmunoz

This comment has been minimized.

Copy link

fsmunoz commented May 5, 2017

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.

@guiambros

This comment has been minimized.

Copy link

guiambros commented Jul 4, 2017

Thanks @fsmunoz! Much appreciated.

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

@ddreggors

This comment has been minimized.

Copy link

ddreggors commented Oct 24, 2017

@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

@fsmunoz

This comment has been minimized.

Copy link

fsmunoz commented Oct 24, 2017

@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.

@ddreggors

This comment has been minimized.

Copy link

ddreggors commented Oct 24, 2017

@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?

@fsmunoz

This comment has been minimized.

Copy link

fsmunoz commented Oct 25, 2017

@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.

@ddreggors

This comment has been minimized.

Copy link

ddreggors commented Oct 25, 2017

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

@aroman

This comment has been minimized.

Copy link

aroman commented Feb 28, 2018

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)

@jhf2442

This comment has been minimized.

Copy link

jhf2442 commented Mar 25, 2018

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

@jessfraz

This comment has been minimized.

Copy link
Owner

jessfraz commented Jun 6, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.