docker-firefox icon indicating copy to clipboard operation
docker-firefox copied to clipboard

Sound - Pulseaudio over TCP

Open s41m0n opened this issue 4 years ago • 12 comments

Hi, I would like to congratulate for your work, is amazing and runs smoothly!

Recently I had to work with this image to enable audio using Pulseaudio over a TCP socket (instead than mapping /dev/snd), but I was not able to accomplish it. I tried to install Pulseaudio and set PULSE_SERVER=tcp:MY_IP:MY_PORT but nothing happens (and perform pactl load-module module-native-protocol-tcp port=MY_PORT auth-ip-acl=DOCKER_IP in the server).

Using a complete ubuntu environment docker it works, but that would not be the best choice for me since I just need the software you use + Pulseaudio, not the entire session.

Do you have some advice? Thanks in advance.

s41m0n avatar Jan 25 '20 18:01 s41m0n

Hi, Looks like Firefox on Alpine is not compiled with pulse audio support: https://git.alpinelinux.org/aports/tree/testing/firefox/APKBUILD#n189

jlesage avatar Feb 10 '20 17:02 jlesage

On Ubuntu, what do you need to make it work? Just setting the PULSE_SERVER variable?

jlesage avatar Feb 10 '20 17:02 jlesage

Hi, thanks for answering, I did not notice the --disable-pulseaudio flag! Yes, in Ubuntu all you have to do is setting the PULSE_SERVER variable (in my case is PULSE_SERVER=tcp:x.x.x.x:port). I try to dig deeper, but you have surely clarified my doubts.

s41m0n avatar Feb 11 '20 00:02 s41m0n

Hi, I tried to test Firefox using your Ubuntu baseimage, but the audio still does not work. Maybe I need to start DBUS or some other services like every startx script does?

s41m0n avatar Feb 11 '20 12:02 s41m0n

Hi and thanks for this good container ;-)

Do we have some clues on how to get the sound? I've found this link that seam to explain well how to get the sound : https://medium.com/@hoxunn/wsl-docker-a-step-closer-to-jess-container-world-b4c4723b3c18 But I'm quite new to Docker. Could someone try and tell if it works?

When @jlesage says "Looks like Firefox on Alpine is not compiled with pulse audio support", does it mean that in any case it won't work as Firefox will not even try to output a sound?

Thanks in advance ;-)

patsej avatar Feb 21 '20 14:02 patsej

Hi everyone, I have just finished to test Firefox sound over tcp in an ubuntu:latest environment and it works! Honestly, I did not have to even specify to install pulseaudio or other packages, since Firefox's installation handles it, surely because it has been compiled with the pulseaudio support (differently from alpine). Thanks for all the support, I was finally able to make everything work, even though in Ubuntu :smile:

s41m0n avatar Feb 26 '20 03:02 s41m0n

Hi Simone, Thanks for the feedback! Sounds exciting :-D @jlesage How hard would it be to integrate Simone's findings? Cheers ;-)

patsej avatar Feb 26 '20 07:02 patsej

Hi Everyone

Could some please help me to play it on Digital Ocean droplet. I am trying to run it sound wont play on m system.

Thanks

vinkvii avatar Apr 25 '20 16:04 vinkvii

My suggestions:

  • check that the application you are willing to run is compiled with audio support (like in our case Firefox in alpine wasnt')
  • make sure your pulseaudio server is enabled to accept that specific connection (pactl load-module module-native-protocol-tcp port=Y auth-ip-acl=X.X.X.X where Y is the local server port, X.X.X.X is the accepted IP/network it belongs, and please check whether you want to support ipv4 or ipv6)
  • make sure to have correctly set in your docker PULSE_SERVER=J:Z.Z.Z.Z:Y: where J is the protocol (tcp/unix socket), Z.Z.Z.Z the server IP and Y the server port

s41m0n avatar Apr 26 '20 17:04 s41m0n

I am running docker-firefox with pulseaudio without problem in wsl2 (Windows Subsystem Linux). It should have no problem in other environment I believe.

As long as your WSL distribution has sound, for this firefox container to have sound, the only caveat is that, the setting for PULSE_SERVER should point to the actual audio server's IP accessible to the container. It is the IP address of the vEthernet of WSL. (You cannot follow other WSL sound guides to set the PULSE_SERVER within the docker-firefox container using its nameserver IP, because the docker container's nameserver is managed by Docker, not WSL).

  1. In a WSL distribution shell that docker runs, pass the correct PULSE_SERVER value to the docker firefox by specifying the environment variable to "docker run" with correct IP value.
> PULSE_SERVER=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
> docker run -d   -e PULSE_SERVER=tcp:$PULSE_SERVER  --name=firefox     -p 5800:5800     -v /docker/appdata/firefox:/config:rw   -v /dev/shm:/dev/shm    --security-opt seccomp=unconfined  jlesage/firefox

  1. Login to the container shell and install the pulseaudio package.
  2. Stop the docker image, and restart it.

Hooray, hit localhost:5800, and youtube plays sound now!

Anyway, an easier way is simply to add the pulseaudio package in the Dockerfile, like below,

diff --git a/Dockerfile b/Dockerfile
index 677ec82..86a6bcd 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -61,7 +61,9 @@ RUN \
         ttf-dejavu \
         ffmpeg-libs \
         # The following package is used to send key presses to the X process.
-        xdotool
+        xdotool \
+       # for audio support in WSL
+       pulseaudio pulseaudio-alsa

 # Set default settings.
 RUN \

I've tried this, and then I can start the container with sound straightforwardly. Still,

  1. You need have your WSL distribution sound set ready before trying this;
  2. You need run the container with PULSE_SERVER environment variable set.

Thanks.

2015xli avatar Jul 17 '20 05:07 2015xli

Hello, does jlesage/firefox:latest (v1.17.1) support Pulseaudio now ?

I am sure Pulseaudio on windows is working, and tested on Ubuntu 20.04 (WSL2), it worked.

But I tried start container with -e PULSE_SERVER=tcp:172.23.224.1 parma, it didn't work.

Than I tried to build image after adding pulseaudio pulseaudio-alsa in Dockerfile which like #60.

Build command docker build -t miyouzi/firefox:0.1 .

But I got an error blow:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-app-niceness.sh: executing...
[cont-init.d] 00-app-niceness.sh: exited 0.
[cont-init.d] 00-app-script.sh: executing...
[cont-init.d] 00-app-script.sh: exited 0.
[cont-init.d] 00-app-user-map.sh: executing...
[cont-init.d] 00-app-user-map.sh: exited 0.
[cont-init.d] 00-clean-logmonitor-states.sh: executing...
[cont-init.d] 00-clean-logmonitor-states.sh: exited 0.
[cont-init.d] 00-clean-tmp-dir.sh: executing...
[cont-init.d] 00-clean-tmp-dir.sh: exited 0.
[cont-init.d] 00-set-app-deps.sh: executing...
[cont-init.d] 00-set-app-deps.sh: exited 0.
[cont-init.d] 00-set-home.sh: executing...
[cont-init.d] 00-set-home.sh: exited 0.
[cont-init.d] 00-take-config-ownership.sh: executing...
[cont-init.d] 00-take-config-ownership.sh: exited 0.
[cont-init.d] 00-xdg-runtime-dir.sh: executing...
[cont-init.d] 00-xdg-runtime-dir.sh: exited 0.
[cont-init.d] 10-certs.sh: executing...
[cont-init.d] 10-certs.sh: exited 0.
[cont-init.d] 10-cjk-font.sh: executing...
[cont-init.d] 10-cjk-font.sh: exited 0.
[cont-init.d] 10-nginx.sh: executing...
[cont-init.d] 10-nginx.sh: exited 0.
[cont-init.d] 10-vnc-password.sh: executing...
[cont-init.d] 10-vnc-password.sh: exited 0.
[cont-init.d] 10-web-index.sh: executing...
[cont-init.d] 10-web-index.sh: exited 0.
[cont-init.d] check-snd.sh: executing...
: No such file or directory sh
[cont-init.d] check-snd.sh: exited 111.
[services.d] stopping services
[services.d] stopping s6-fdholderd...
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] syncing disks.
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.

PS: I cannot use --device /dev/snd parma,It said error gathering device information while adding custom device "/dev/snd": no such file or directory.

miyouzi avatar Jul 16 '21 11:07 miyouzi

Hello, does jlesage/firefox:latest (v1.17.1) support Pulseaudio now ?

I am sure Pulseaudio on windows is working, and tested on Ubuntu 20.04 (WSL2), it worked.

But I tried start container with -e PULSE_SERVER=tcp:172.23.224.1 parma, it didn't work.

Than I tried to build image after adding pulseaudio pulseaudio-alsa in Dockerfile which like #60.

Build command docker build -t miyouzi/firefox:0.1 .

But I got an error blow:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-app-niceness.sh: executing...
[cont-init.d] 00-app-niceness.sh: exited 0.
[cont-init.d] 00-app-script.sh: executing...
[cont-init.d] 00-app-script.sh: exited 0.
[cont-init.d] 00-app-user-map.sh: executing...
[cont-init.d] 00-app-user-map.sh: exited 0.
[cont-init.d] 00-clean-logmonitor-states.sh: executing...
[cont-init.d] 00-clean-logmonitor-states.sh: exited 0.
[cont-init.d] 00-clean-tmp-dir.sh: executing...
[cont-init.d] 00-clean-tmp-dir.sh: exited 0.
[cont-init.d] 00-set-app-deps.sh: executing...
[cont-init.d] 00-set-app-deps.sh: exited 0.
[cont-init.d] 00-set-home.sh: executing...
[cont-init.d] 00-set-home.sh: exited 0.
[cont-init.d] 00-take-config-ownership.sh: executing...
[cont-init.d] 00-take-config-ownership.sh: exited 0.
[cont-init.d] 00-xdg-runtime-dir.sh: executing...
[cont-init.d] 00-xdg-runtime-dir.sh: exited 0.
[cont-init.d] 10-certs.sh: executing...
[cont-init.d] 10-certs.sh: exited 0.
[cont-init.d] 10-cjk-font.sh: executing...
[cont-init.d] 10-cjk-font.sh: exited 0.
[cont-init.d] 10-nginx.sh: executing...
[cont-init.d] 10-nginx.sh: exited 0.
[cont-init.d] 10-vnc-password.sh: executing...
[cont-init.d] 10-vnc-password.sh: exited 0.
[cont-init.d] 10-web-index.sh: executing...
[cont-init.d] 10-web-index.sh: exited 0.
[cont-init.d] check-snd.sh: executing...
: No such file or directory sh
[cont-init.d] check-snd.sh: exited 111.
[services.d] stopping services
[services.d] stopping s6-fdholderd...
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] syncing disks.
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.

PS: I cannot use --device /dev/snd parma,It said error gathering device information while adding custom device "/dev/snd": no such file or directory.

I think I found where is the problem. The Dockerfile can't be edited in Windows, that will add may unnecessary chars at the end of line, using git diff can see it.

Using vim in wsl to edit Dockerfile and then build will solve the problem.

miyouzi avatar Jul 18 '21 14:07 miyouzi