run apps using audio in a docker container

前端 未结 4 847
失恋的感觉
失恋的感觉 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 15:13

    Inspired by the links you've posted, I was able to create the following solution. It is as lightweight as I could get it. However, I'm not sure if it is (1) secure, and (2) entirely fits your use-case (as it still uses the network).

    1. Install paprefson your host system, e.g. using sudo apt-get install paprefs on an Ubuntu machine.
    2. Launch PulseAudio Preferences, go to the "Network Server" tab, and check the "Enable network access to local sound devices" checkbox [1]
    3. Restart your computer. (Only restarting Pulseaudio didn't work for me on Ubuntu 14.10)
    4. Install Pulseaudio in your container, e.g. sudo apt-get install -y pulseaudio
    5. In your container, run export "PULSE_SERVER=tcp::". For example, export "PULSE_SERVER=tcp:172.16.86.13:4713" [2]. You can find out your IP address using ifconfig and the Pulseaudio port using pax11publish [1].
    6. That's it. Step 5 should probably be automated if the IP address and Pulseaudio port are subject to change. Additionally, I'm not sure if Docker permanently stores environment variables like PULSE_SERVER: If it doesn't then you have to initialize it after each container start.

    Suggestions to make my approach even better would be greatly appreciated, since I'm currently working on a similar problem as the OP.

    References:
    [1] https://github.com/jlund/docker-chrome-pulseaudio
    [2] https://github.com/jlund/docker-chrome-pulseaudio/blob/master/Dockerfile

    UPDATE (and probably the better solution):
    This also works using a Unix socket instead of a TCP socket:

    1. Start the container with -v /run/user/$UID/pulse/native:/path/to/pulseaudio/socket
    2. In the container, run export "PULSE_SERVER=unix:/path/to/pulseaudio/socket"

    The /path/to/pulseaudio/socket can be anything, for testing purposes I used /home/user/pulse.
    Maybe it will even work with the same path as on the host (taking care of the $UID part) as the default socket, this way the ultimate solution would be -v /run/user/$UID/pulse/native:/run/user//pulse; I haven't tested this however.

提交回复
热议问题