How to setup Nvidia HW acceleration in Ubuntu Docker?

I was hoping to grab a Geforce 1050 for around 50$ to add two more 4k transcodes to my server. Currently my dual Xeon x5690 can handle 2 4K transcodes at once, adding 2 more would help a lot. I know that when you use docker, Plex doesnt get low level access to the GPU. There is a way around this. Does anyone know what that way around is?

Pretty much asking how to give low level access to the GPU in a docker container in Ubuntu.

1 Like

It’s not quite straight forward

Assuming you were able to get this deployed, does Plex actually support load balancing transcode duties across both CPU and GPU?

I believe it does. I didn’t get it running yet though. I’m redoing everything in unraid this week.

An alternative is to run just Plex in a VM… then you can do pass-through and put everything else in another VM using dockers.
Friend of mine said he got his card + onboard working at the same time under unraid.

That was my exact plan lol

I have had success with deploying the standard Plex docker and have it running with the " NVIDIA Container Runtime" this is run on a Ubuntu 18.04, 2.2ghz 64core 4x cpu & a Quadro p400 for GPU.

Currently I am able to run inside the container Nvidia-smi and my GPU shows up with Plex docker because I run it with the Nvidia runtime. (Note I was able to get Plex to use the GPU when running Plex on bare metal outside of docker)

This has all been good signs but I am still unable to get Plex to encoded or decode with the GPU. I have tried giving the Plex container privilege as well as specific device privilege for all /dev/nvidia Dev’s.

No luck so for any help guys would be great.

1 Like

@ZeRoSyNC, Not sure if you ever figured it out, but I’ve been attempting to do the same thing for the past couple of days and finally managed to! Since this thread came up close to the top when I googled, I figured I’d add my two cents so hopefully it takes the next person less time than it took me to get it working.

I did this on OpenMediaVault 4.0, which is based on Debian 9. I imagine it’s almost exactly the same on other distributions.

Obviously, first install the Linux Nvidia driver for your GPU and make sure it’s working.

Then install nvidia-docker2 (these instructions from https://github.com/NVIDIA/nvidia-docker)

# Add the package repositories
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
  sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
  sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update

# Install nvidia-docker2 and reload the Docker daemon configuration
sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd

# Test nvidia-smi with the latest official CUDA image
docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi

Once that is all set up, when you configure the plex docker container, add the environment variables:

NVIDIA_VISIBLE_DEVICES all
NVIDIA_DRIVER_CAPABILITIES compute,video,utility

and add the switch

--runtime=nvidia

to your run/create command, i.e.

docker create \
--runtime=nvidia \
--name=plex \
--net=host \
-e NVIDIA_VISIBLE_DEVICES=all \
-e NVIDIA_DRIVER_CAPABILITIES=compute,video,utility \
-e VERSION=latest \
-e PUID=<UID> -e PGID=<GID> \
-e TZ=<timezone> \
-v </path/to/library>:/config \s
-v <path/to/tvseries>:/data/tvshows \
-v </path/to/movies>:/data/movies \
-v </path for transcoding>:/transcode \
linuxserver/plex

that’s all it took to get my GPU to be enabled in docker!


Surprisingly easy in the end after going down many wrong paths!

EDIT: Added steps to add nvidia-docker repo

3 Likes

Thanks!!!

Just a correction:

docker run \
--runtime=nvidia \
--name=plex \
--net=host \
-e NVIDIA_VISIBLE_DEVICES=all \
-e NVIDIA_DRIVER_CAPABILITIES=compute,video,utility \
-e VERSION=latest \
-e PUID=<UID> -e PGID=<GID> \
-e TZ=<timezone> \
-v </path/to/library>:/config \
-v <path/to/tvseries>:/data/tvshows \
-v </path/to/movies>:/data/movies \
-v </path for transcoding>:/transcode \
linuxserver/plex
1 Like

One caveat everyone here should be aware of is the lack of decode support. Only encoding currently works with Plex Transcoder. Vote for that to change here: Hardware Accelerated Decode (Nvidia) for Linux

Yes, and some are trying to compile ffmpeg and enable NVDEC there too.

But it is really time for Plex to enable it. There is no reason not to, I haven’t seen any reports of stability or quality implications and it’s been out for at least a year.

I’ve just added an Nvidia P2000 to my server, and have followed the steps listed by cmuellersmith but am still not seeing Plex use hardware transcoding. The nvidia-smi test works find though. Any ideas on what might not be working here? I’m running Debian 9, and have tested with the official Plex docker as well as the linuxserver one.

The UID of your docker needs to be added to the video group. Also doesn’t hurt to add:

--device=/dev/dri:/dev/dri \

to your dockerfile

I didn’t have to add the docker UID to the video group for it to work, nor did I have to add the device line to the docker file, so I suspect neither of those are the problem, although doing the former probably doesn’t hurt just to be sure.

@judsonmartin23, I suppose the first basic question is did you check the box to use it in your server settings (you have to show advanced settings to see it)? If you did, I did find that installing the Nvidia drivers from the Nvidia site seemed to install all the necessary components, but if I installed them using apt then some were missing. I figured out what I needed to install from looking at the Plex logs (you can find lines where it says it failed to load a cuda shared library when trying to transcode). I think it was just the libnvidia-encode1 and maybe the libnvcuvid1 packages. When I installed, I used the stretch-backports repository because I think the regular stretch repository’s driver version was tool old to support my card, so that might be another thing to check.

Appreciate all the help! I do have “Use hardware acceleration when available” checked in the transcoder settings. I’ll take a dig through the log looking for missing packages as well. I also installed the drivers via apt but just the most current ones, not the backports.

I won’t have time to try these until tonight so I’ll post an update then - if I can’t find a missing package then I’ll try adding the UID to the video group and adding the device line as well.

Edit: That worked! I needed the nvidia-encode1 package; it was clear enough once digging into the log file. Thanks again!

hi Guys!

Trying to accomplish the same on an Unraid server and the Official PLEX docker. I installed the NVIDIA plugin from someone that created it and that added the Nvidia to Unraid OS. The rest of instructions was to use a docker with the Driver installed in it, it’s what i don’t know how to do… any help appreciate to have this working!

Great write-up!

Just a note for anyone using more than one GPU, you can specify which is used in docker by changing all to the gpu UUID.

Run this to get GPU UUIDs

nvidia-smi -L

change all to the UUID

NVIDIA_VISIBLE_DEVICES all
NVIDIA_VISIBLE_DEVICES GPU-05e8b0fb-091b-3621-9d91-5f056d548121

Has something changed? I can’t seem to HW encode anymore with the latest Plex (beta & pass). I verified that nvidia-docker is running and is the default runtime. I have the latest docker & nvidia-docker.

Plex 1.15.3.876 - Ubuntu - docker - nvidia-docker

Hey bud you still need some help? I’ve had and solved this problem about 5 times.

Thank you but I ended up going a different route. I am coming back to unraid in a few weeks though. I think there is a lot of new stuff though on how to get this working.