Plex transcoding with Docker – NVIDIA GPU

Plex

Introduction

To use Plex transcoding with Docker we need to passtrough the NVIDIA GPU to the Docker container. Plex has the ability to fully use the NVIDIA GPU for video transcoding like a bare metal install. In this post I will explain the needed steps to get Plex transcoding to work. In this example we will use Ubuntu 22.04

Update (02-09-2024) – driver version 550

Updates the post with the latest NVIDIA container install commands and drivers version 550. Let me know if everything still works okay in the comments!

NVIDIA drivers server

First we need to install the NVIDIA driver. On Ubuntu or Debian based systems we can install the drivers from apt. As this is a server without a GUI we will go for the headless drivers. After installing the NVIDIA driver we also need to install the package libnvidia-encode for the video transcoding.

# Search apt for NVIDIA drivers.
sudo apt search nvidia-driver
# At the time of writing the latest driver is 550.

# Install the headless server drivers.
sudo apt install nvidia-headless-550-server

# Install the NVIDIA Utils
sudo apt install nvidia-utils-550-server

# Search apt for libnvidia-encode. Needed for Plex transcoding
sudo apt search nvidia-encode

# Install the libnvidia-encode package.
sudo apt install libnvidia-encode-550-server

After installing all the packages reboot your server and check if everything works correctly with the nvidia-smi command.

nvidia-smi

# Output
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.73.05    Driver Version: 510.73.05    CUDA Version: 11.6     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Quadro P2000        Off  | 00000000:0B:00.0 Off |                  N/A |
| 44%   31C    P8     5W /  75W |      2MiB /  5120MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

NVIDIA container toolkit

After installing the drivers we need to install the NVIDIA container toolkit. More information about the NVIDIA container toolkit can be found on the NVIDIA docs site.

Setting up the package repository

# Add the gpgpkey and repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg   && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list |     sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' |     sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.lis

Installing the NVIDIA container toolkit

# Update and install NVIDIA Container Toolkit
sudo apt-get update

sudo apt-get install -y nvidia-container-toolkit

# Configure NVIDIA Container Toolkit
sudo nvidia-ctk runtime configure --runtime=docker

sudo systemctl restart docker

# Test GPU integration
docker run --gpus all nvidia/cuda:11.5.2-base-ubuntu20.04 nvidia-smi

Docker compose options

After all the local packages we need to configure our Docker compose file to use the NVIDIA GPU inside the Plex container. I will assume you have the latest version of Docker installed with the new Docker compose version. Below is an example of my Docker compose file for Plex transcoding with Docker.

Important

When using this guide you need the use the LinuxServer.io Plex Docker image. The official image is missing NVIDIA packages that prevent transcoding from working correctly.

---
version: "3.8"
services:
  plex:
    image: lscr.io/linuxserver/plex:latest
    container_name: plex
    network_mode: host
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]

    environment:
      - PUID=1001
      - PGID=1001
      - VERSION=docker
      - PLEX_CLAIM=##CLAIM-TOKEN##
      - NVIDIA_VISIBLE_DEVICES=all
      - NVIDIA_DRIVER_CAPABILITIES=compute,video,utility
    volumes:
      - /home/tizu/plex/appdata/config:/config
      - /mnt/media/TV Shows:/tv
      - /mnt/media/Movies:/movies
      - /mnt/media/Music:/music
    restart: unless-stopped

Next spin up the Docker stack and test the transcoding. In Plex you need to make sure it says Transcode (hw) when transcoding a video. For example:

Transcode (hw)

Conclusion

It took me quite a while to get this setup working correctly. The most important thing I was missing was the libnvidia-encode package. For another example with Ollama head over to my NVIDIA GPU with Docker post I hope this post helps you out getting the NVIDIA transcoding working in Plex. If you have any questions leave them in the comments!

If you are looking for a great deal for a graphics card. Click the link below!

Graphic Cards

12 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Yeah I needed to specify more detail in the compose file to get it up and running.

    deploy:
    resources:
    reservations:
    devices:
    – driver: nvidia
    count: 1
    capabilities: [gpu]

  2. For anyone else scratching their head, not running docker compose, but instead docker run (following the official plex docker guide), add the –gpus all flag at the end of the run command (as shown in the cuda test).

  3. Tried this the other night and it didn’t work for me got nvidia-smi output and the test cuda image did what it was support to do with nvidia-smi output but my plex docker will not spin up when enabling the gpu option.

    Any suggestions on how to troubleshoot this issue “Cannot read properties of null (reading ‘push’)” in portainer after adding env and turning on GPU

  4. Thanks so much for this! I finally got this working after trying a bunch of times over the course of a year. Now, to see if this actually helps concurrent streams transcoding…

  5. I’ve followed a few too many guides, but this one worked for me. Appreciate the detailed write up, this was quick and got hw transcodes working!

  6. Hi! I followed the tutorial and everything worked well until i can’t see the “Transcode (hw)” part.
    nvidia-smi shows my NVIDIA GPU without no problem.

    I entered in PLEX support webpage and says that function can only be enabled with plex-pass.

  7. Hello,

    I am attempting to install the drivers, also on Ubuntu 22.04.
    I don’t see any “headless” offerings in the search results.