Comments (21)
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-unix
module 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.
Bit late to the party, but if anyone still wants to get it working on desktop with PulseAudio:
-
Add
load-module module-native-protocol-tcp
to/etc/pulse/default.pa
& restart PA -
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
-
Pass PA address to the container as
PULSE_SERVER
(tcp:localhost:4713
is a default formodule-native-protocol-tcp
):-e PULSE_SERVER=tcp:localhost:4713
-
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.
Or try --group-add audio on run
from dockerfiles.
to keep it short:
--group-add $(getent group audio | cut -d: -f3)
from dockerfiles.
I get sound working with chromium executed as a "normal" user (uid 1000).
- Maybe you need dbus and shm inside the container
-v /run/dbus/:/run/dbus/ -v /dev/shm:/dev/shm
-
The user have to be member of the audio group inside the container (isn't needed outside...)
-
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.
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.
@lidel: Nice, that solution gave my containers the power of sound 😄
Tested on:
Ubuntu 16.04.1 LTS x86_64
Docker v1.11.2
PulseAudio v8.0
Build Code:
bvb5hx648ezythwbrehtzia
from dockerfiles.
The problem is probably pulseaudio on your host interfering
from dockerfiles.
I would look at the other issues in this repo wrt to sound and see if any of them fix it
from dockerfiles.
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.
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.
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.
@atilaromero solution worked for me!
from dockerfiles.
Thanks @fsmunoz! Much appreciated.
This worked for me, host on ubuntu 14.04 using Pulse Audio.
from dockerfiles.
@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.
@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.
@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.
@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.
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.
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.
this should be fixed or working now but let me know if otherwise
from dockerfiles.
Related Issues (20)
- novice question - bug HOT 2
- cathode - error during build HOT 1
- jess/firefox ESNI is broken HOT 3
- dockerfile config changes
- tor-browser/dockerfile: version 9.0.10 not available
- official website for jessfraz/pastebinit seems down
- docker hub profile disambiguation
- jess/firefox won't start HOT 3
- Consider firefox image updates for stable tracks HOT 1
- Consider Alpine Linux foundation for Firefox and Chromium
- Using audio on the jess/pulseaudio container, with Podman and Mac OS
- Q - In the chromium Dockerfile, is the add user step necessary?
- Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted HOT 1
- Dockerfile for Logseq Desktop?
- the jess/virtualbox docker image how can use
- Docker images not updated since 2023-06-13 HOT 4
- Dick
- GitHub CLI | Take GitHub to the command line
- New
- . yu
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dockerfiles.