GPU support in container

does the container support gpus or more specifically, a nvidia gpu, for hardware acceleration? how much trouble would it be to add it myself?

I have hardware acceleration enabled in plex itself but it’s not using the gpu yet. I’m not sure exactly what I’m missing but I’m beginning to feel like I need to switch to the official plex image, I just like how the linuxserver.io images are built over the rest.

I have gpu support working in docker itself as evident by nvidia’s own test container for nvidia-smi.

this is my current config.

  plex:
    image: linuxserver/plex:amd64-1.22.1.4228-724c56e62-ls35
    container_name: plex
    network_mode: host
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [video]
    devices:
      - /dev/dri:/dev/dri
    environment:
      - PUID=1000
      - PGID=1000
      - VERSION=docker
      - UMASK_SET=022 #optional
      - PLEX_CLAIM= #optional
      - NVIDIA_VISIBLE_DEVICES=all
      - NVIDIA_DRIVER_CAPABILITIES=video
    volumes:
      - /var/lib/plexmediaserver:/config
      - /media:/media
      - /transcoder:/transcoder
      - /etc/resolv.conf:/etc/resolv.conf
    restart: unless-stopped

Yep, our Plex container supports Nvidia gpu’s just fine (along with our emby and jellyfin containers too)

I assume you have all the correct drivers + docker runtime installed on the host?

yes, I have the headless server drivers and docker runtime installed.

I can see the gpu with docker run --rm --gpus all nvidia/cuda:11.4.0-base-ubuntu20.04 nvidia-smi.

^^^ this thread.

I am having the same issue. My previous setup it worked but the container wasn’t updated to the latest version. Any suggestions?

Start plex with the docker run command and see if that works. If so, then you have an issue with your compose yaml (there were some changes a little while ago with regards to using gpus in compose yaml)

well do you see any issues with my compose file? am I missing something? I have the latest docker-compose binary which is why I was able to even run my config as it is now. (I cut the unneeded bits for this post though)

This worked for me.

The only GPU parameters I needed were: --runtime=nvidia
-e NVIDIA_VISIBLE_DEVICES=all

Try this:

 plex:
    image: ghcr.io/linuxserver/plex
    container_name: plex
    network_mode: host
    runtime: nvidia
    environment:
      - PUID=1000
      - PGID=1000
      - VERSION=docker
      - UMASK_SET=022 #optional
      - PLEX_CLAIM= #optional
      - NVIDIA_VISIBLE_DEVICES=all
    volumes:
      - /var/lib/plexmediaserver:/config
      - /media:/media
      - /transcoder:/transcoder
      - /etc/resolv.conf:/etc/resolv.conf
    restart: unless-stopped

alright, so I made the changes to my compose file and recreated the plex container. I can run nvidia-smi and see my gpu there in my plex container but it still isn’t using the gpu. :confused:

Do you have plexpass?

I do.

Try using the run command to see if it works.

what would that accomplish if the gpu is already exposed to the plex container?

I see this regardless of if a video is playing or not. so something is up with plex I think. :confused:

┌─[michael@fileserver]─[~/services/plex]
└──╼ $docker-compose exec plex nvidia-smi
Sun Jul 25 14:58:57 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.91.03    Driver Version: 460.91.03    CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| 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 P400         Off  | 00000000:01:00.0 Off |                  N/A |
| 34%   36C    P8    N/A /  N/A |      2MiB /  1999MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

I still see errors like this in my plex server logs as well.

Jul 25, 2021 01:22:47.380 [0x7f421964ab38] ERROR - [Transcode] [FFMPEG] - Cannot load libnvidia-encode.so.1
Jul 25, 2021 01:22:47.380 [0x7f421964ab38] ERROR - [Transcode] [FFMPEG] - The minimum required Nvidia driver for nvenc is 418.30 or newer
Jul 25, 2021 01:22:47.426 [0x7f421964ab38] WARN - [Transcode] Codecs: avcodec_open2 returned -1 for encoder 'h264_nvenc'
Jul 25, 2021 01:22:47.509 [0x7f421964ab38] ERROR - [Transcode] [FFMPEG] - Cannot load libnvcuvid.so.1
Jul 25, 2021 01:22:47.509 [0x7f421964ab38] ERROR - [Transcode] [FFMPEG] - Failed loading nvcuvid.
Jul 25, 2021 01:22:47.509 [0x7f421964ab38] ERROR - [Transcode] [FFMPEG] - Failed setup for format cuda: hwaccel initialisation returned error.
Jul 25, 2021 01:22:47.543 [0x7f421964ab38] WARN - [Transcode] Codecs: avcodec_open2 returned -95 for decoder 'hevc'
Jul 25, 2021 01:22:47.611 [0x7f421964ab38] ERROR - [Transcode] [FFMPEG] - Cannot load libnvidia-encode.so.1
Jul 25, 2021 01:22:47.611 [0x7f421964ab38] ERROR - [Transcode] [FFMPEG] - The minimum required Nvidia driver for nvenc is 418.30 or newer
Jul 25, 2021 01:22:47.642 [0x7f421964ab38] WARN - [Transcode] Codecs: avcodec_open2 returned -1 for encoder 'h264_nvenc'
Jul 25, 2021 01:22:47.710 [0x7f421964ab38] ERROR - [Transcode] [FFMPEG] - Cannot load libnvcuvid.so.1
Jul 25, 2021 01:22:47.710 [0x7f421964ab38] ERROR - [Transcode] [FFMPEG] - Failed loading nvcuvid.
Jul 25, 2021 01:22:47.710 [0x7f421964ab38] ERROR - [Transcode] [FFMPEG] - Failed setup for format cuda: hwaccel initialisation returned error.
Jul 25, 2021 01:22:47.742 [0x7f421964ab38] WARN - [Transcode] Codecs: avcodec_open2 returned -95 for decoder 'hevc'

what am I still missing here?

That’s telling you that you need a newer driver on your host.

except that I do, as evident by my nvidia-smi output. I have the headless 460 server drivers installed.

well this is promising… I installed the package “libnvidia-encode-460-server” and restarted the plex container. now I see a new process in the nvidia-smi on the host side. a process consuming 232MiB of vram. Strangely, it doesn’t appear in the nvidia-smi output within the container.

Plex is reporting hardware transcoding in the server dashboard now so that’s nice.

4k transcoding to my desktop doesn’t work so well though. it’s buffering a lot but is using the gpu though. one problem solved for another. lol

Atleast it’s working now, Just don’t transcode 4k :+1:

well it was kinda the whole point of getting the gpu, to be able to play a 4k film once in a while.

but it looks like with a quadro p400, it can run about 8 1080p streams if I wanted to. XD only limit is upload bandwidth for remote users.

nvidia-smi shows the processes only when run on the host