run apps using audio in a docker container

前端 未结 4 848
失恋的感觉
失恋的感觉 2020-12-12 14:53

This question is inspired by Can you run GUI apps in a docker container?.

The basic idea is to run apps with audio and ui (vlc, firefox, skype, ...)

I was se

4条回答
  •  粉色の甜心
    2020-12-12 14:55

    After trying most of the solutions described here I found only PulseAudio over network to be really working. However you can make it safe by keeping the authentication.

    1. Install paprefs (on host machine):

      $ apt-get install paprefs
      
    2. Launch paprefs (PulseAudio Preferences) > Network Server > [X] Enable network access to local sound devices.

    3. Restart PulseAudio:

      $ service pulseaudio restart
      
    4. Check it worked or restart machine:

      $ (pax11publish || xprop -root PULSE_SERVER) | grep -Eo 'tcp:[^ ]*'
      tcp:myhostname:4713
      

    Now use that socket:

    $ docker run \
        -e PULSE_SERVER=tcp:$(hostname -i):4713 \
        -e PULSE_COOKIE=/run/pulse/cookie \
        -v ~/.config/pulse/cookie:/run/pulse/cookie \
        ...
    

    Check that the user running inside the container has access to the cookie file ~/.config/pulse/cookie.

    To test it works:

    $ apt-get install mplayer
    $ mplayer /usr/share/sounds/alsa/Front_Right.wav
    

    For more info may check Docker Mopidy project.

提交回复
热议问题