Using hardware acceleration in docker

I’m trying to use hardware acceleration inside my docker container (using wernight/plex-media-server:autoupdate image) and it fails.

I have a AMD HD6950 and an Intel i7-2700k iGPU. I know that plex will not work on the AMD card, but I’d like to use the iGPU.
Note that my motherboard does not have an output for the iGPU.

Here is the output of sudo lshw -c video on the host and inside the container:

*-display
description: VGA compatible controller
product: Cayman PRO [Radeon HD 6950]
vendor: Advanced Micro Devices, Inc. [AMD/ATI]
physical id: 0
bus info: pci@0000:04:00.0
version: 00
width: 64 bits
clock: 33MHz
capabilities: pm pciexpress msi vga_controller bus_master cap_list rom
configuration: driver=radeon latency=0
resources: irq:50 memory:e0000000-efffffff memory:f7d20000-f7d3ffff ioport:d000(size=256) memory:f7d00000-f7d1ffff
*-display
description: Display controller
product: 2nd Generation Core Processor Family Integrated Graphics Controller
vendor: Intel Corporation
physical id: 2
bus info: pci@0000:00:02.0
version: 09
width: 64 bits
clock: 33MHz
capabilities: msi pm bus_master cap_list
configuration: driver=i915 latency=0
resources: irq:53 memory:f7000000-f73fffff memory:d0000000-dfffffff ioport:f000(size=64)

Here is the output of lsmod | grep i915 on the host:

i915 1232896 0
i2c_algo_bit 16384 2 i915,radeon
drm_kms_helper 155648 2 i915,radeon
drm 364544 5 ttm,i915,drm_kms_helper,radeon
video 40960 2 i915,asus_wmi

Here is the output of lspci | grep VGA on the host and inside the container:

04:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Cayman PRO [Radeon HD 6950]

Inside the container, vainfo gives me the following output:

vainfo

error: XDG_RUNTIME_DIR not set in the environment.
error: can’t connect to X server!
libva info: VA-API version 0.39.4
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/gallium_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

My container has --device=/dev/dri:/dev/dri and I also did a chmod -R 777 /dev/dri (I know it’s bad practice, just trying to test things out).

If anyone has any clue, I’d really appreciate some help!

Thanks

I finally managed to make it work by explicitly mapping the correct device, i.e. I mapped the Intel iGPU only (since AMD cards are not supported).

To do so, simply use --device=/dev/dri/card1:/dev/dri/card0 --device /dev/dri/renderD129:/dev/dri/renderD128
Of course, adapt the number avec cardX and renderDXYZ to match your system.

Hi. I’m using plex in a docker with a intel j3455 nas server running openmediavault. I can’t make hardware acceleration working with this configuration. Before i had plex in OMV plugin and it worked with H.A. I’m a plex pass user of course.
Thanks

I just found this in plex articles
Can I use Hardware-Accelerated Streaming inside of Docker?
At this time, we do not formally support hardware acceleration inside of a Docker container. Some users of Docker (on Linux only) have been able to accomplish this by adding platform-specific custom configurations that expose host hardware to the container.

Somebody knows this openmediavault “platform-specific custom configurations that expose host hardware to the container”?

@gravufo I PMed you as well but ill post this here too.

Think you can help me map my Nvidia 1050 to let Plex use HW acceleration? The command you used sudo lshw -c video, you said you ran it inside docker. What command did you use to get into docker? Did you just run sudo lshw -c video in terminal without anything else?

Can you expand on this? “Of course, adapt the number avec cardX and renderDXYZ to match your system.”

Hey there,
I’ll answer here since your questions are of general knowledge and can help anyone.
There are multiple ways to execute commands inside your docker container. You can simply docker exec <container name or ID> 'command' or attach to the container using docker attach <container name or ID> /bin/bash.
I suggest you get familiar with docker and how it works before going into deeper setups. The reference is your friend: https://docs.docker.com/engine/reference/commandline/docker/

As for your second question, if you do ls /dev/dri you’ll see that you can have multiple card*, controlD* and renderD*. You have to select the one that matches the graphics card you want to use. Unfortunately, it’s not that easy to figure out which is which, but you can search on the Internet to figure it out. Of course, if you only have one video device, then you shouldn’t have this issue and you should be able to simply mount /dev/dri inside your container.

Hope this helps!

so docker exec plex ‘sudo lshw -c video’

and I have a video chip for the server and then the 1050. I dont see where in the logs you posted is the controlD or renderD or did you not post that?

I did not post any logs. My post was clear enough. You need to execute ls /dev/dri on your host to figure out which video devices are available on your machine. Then, you need to figure out which one is the one you want to mount inside your docker container. In my case, I had to add the following options in my docker run command: --device=/dev/dri/card1:/dev/dri/card0 --device=/dev/dri/renderD129:/dev/dri/renderD128

1 Like

I installed the native plugin as well still it doesn’t seem to use hw acceleration. :frowning:

Are there any specific steps you took to fix the issue?

So I finally got it! I think there may be security implications to giving the devices all privileges, but it’s running on a container on a home system that I patch regularly.

docker exec -it plex /bin/bash
chmod 777 /dev/dri
exit

Didn’t even have to restart the container

So trying to do the same here, funny thing is that i first tested it out without using docker and got it to work. Then reinstalled the box and now trying to use it with docker but no luck so far.

Also i noticed you guys said that you see a (hw) symbol in the now playing. At the point i did have it working in the non docker environment it did not show this but cpu wise it was 1000% vs 40% so pretty sure it did work then (tested several 4k streams)

I have my /dev/dri , my modprobe worked fine and i tried the chmod 777 everything but i see no change.

Anybody has the hidden gem for me?

Update: running around on the big internet, i tried adding a “privileged: true” and poof it adds the (hw) text to it now. So it seems to be ok, but on this particular setup i cannot run privileged. So what paths /dev/ things am i missing to make this work without it?

Update2: Sep 24, 2018 00:11:55.407 [0x7f23e0bff700] DEBUG - Codecs: testing h264_nvenc (encoder)
Sep 24, 2018 00:11:55.407 [0x7f23e0bff700] ERROR - [FFMPEG] - Cannot load libcuda.so.1
Sep 24, 2018 00:11:55.407 [0x7f23e0bff700] WARN - avcodec_open2 returned -1313558101 for encoder ‘h264_nvenc’
Sep 24, 2018 00:11:55.407 [0x7f23e0bff700] DEBUG - MDE: Cannot direct stream video stream due to profile or setting limitations
Sep 24, 2018 00:11:55.407 [0x7f23e0bff700] DEBUG - Codecs: hardware transcoding: testing API vaapi
Sep 24, 2018 00:11:55.408 [0x7f23e0bff700] ERROR - [FFMPEG] - No VA display found for device: /dev/dri/renderD128.
Sep 24, 2018 00:11:55.408 [0x7f23e0bff700] DEBUG - Codecs: hardware transcoding: opening hw device failed - probably not supported by this system, error: Invalid argument

Even though /dev/dri is mapped to the container. (and has more then the normal rights)

Team,

I know that I’m just a few millimetres away. I’m running the official plex container e.g.
plexinc/pms-docker

This is the LSHW -c video from within the docker container.
root@plex:/# lshw -c video *-display
description: VGA compatible controller
product: NVIDIA Corporation
vendor: NVIDIA Corporation
physical id: 0
bus info: pci@0000:04:00.0
version: a1
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
configuration: driver=nvidia latency=0
resources: irq:96 memory:fa000000-faffffff memory:e0000000-efffffff memory:f0000000-f1ffffff ioport:e000(size=128) memory:fb000000-fb07ffff

I would think I’m good since I can see the one Nvida card that is in the Qnap already from the Plex environment? But I don’t get any symbols for HW acceleration. Do I need to mount it beyond being able to see it?

Might sound stupid, but did you enable the hardware encoding/decoding in plex server settings?

absolutely

Is the issue that I don’t have a proper driver running?

root@plex:/# lshw -c video

*-display UNCLAIMED

   description: VGA compatible controller                                                                                                                                                                           

   product: NVIDIA Corporation                                                                                                                                                                                      

   vendor: NVIDIA Corporation                                                                                                                                                                                       

   physical id: 0                                                                                                                                                                                                   

   bus info: pci@0000:04:00.0                                                                                                                                                                                       

   version: a1                                                                                                                                                                                                      

   width: 64 bits                                                                                                                                                                                                   

   clock: 33MHz                                                                                                                                                                                                     

   capabilities: pm msi pciexpress vga_controller cap_list                                                                                                                                                          

   configuration: latency=0                                                                                                                                                                                         

   resources: memory:fa000000-faffffff memory:e0000000-efffffff memory:f0000000-f1ffffff ioport:e000(size=128) memory:fb000000-fb07ffff

That would indeed be possible.
Try running vainfo and see if it works. Paste the output here if not.
Note that vainfo is probably not installed by default so make sure to install it first.

Mate,

You are correct on it not being in my container. I’m having some issues with aptitude. Do you know if there is a command to just have it rebuilt and update all packages based on deps automagically?

Got that sorted and ran vainfo:

root@plex:/etc/apt# vainfo

error: XDG_RUNTIME_DIR not set in the environment.

error: can’t connect to X server!

error: failed to initialize display

Aborted

Simplest way would be to just run it as privileged, i don’t like it but nobody has the correct things/rights that need to be linked in the container for it to work.

p.s. can’t connect to X server just means you don’t have X running (your linux desktop)