昔年浅巷

昔年浅巷

PLEX-DOCKER部署支持硬解码

305
2024-10-19

显卡驱动安装

系统:ubuntu23.04

显卡:英伟达RTX2060

输入以下命令安装:

## 搜索最适合的显卡驱动
root@hzaw-pt:~# nvidia-detector 
nvidia-driver-535

## 安装驱动
root@hzaw-pt:~# apt-get install -y nvidia-driver-535

## 安装完成后重启,并运行以下命令查看是否启动成功
root@hzaw-pt:~# nvidia-smi
Sun Sep 24 21:57:17 2023       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.86.05              Driver Version: 535.86.05    CUDA Version: 12.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  NVIDIA GeForce RTX 2060        Off | 00000000:09:00.0 Off |                  N/A |
|  0%   45C    P8               3W / 160W |     14MiB /  6144MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1446      G   /usr/lib/xorg/Xorg                            9MiB |
|    0   N/A  N/A      1545      G   /usr/bin/gnome-shell                          2MiB |
+---------------------------------------------------------------------------------------+


## 安装DOCKER显卡协助工具

## 切换显卡仓库
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.list \
  && \
    sudo apt-get update
    
## 安装显卡驱动
sudo apt-get install -y nvidia-container-toolkit

## 安装docker 显卡依赖
sudo apt-get install -y nvidia-docker2

sudo systemctl restart docker


## 测试容器显卡驱动
sudo docker run --rm --gpus all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi

安装PLEX,并打开显卡驱动

version: "3.8"
services:
  plex:
    image: lscr.io/linuxserver/plex:##指定版本##
    container_name: plex-gpu
    network_mode: host
    deploy:
      resources:
        reservations:
          devices:
            - capabilities: [gpu]
    environment:
      - PUID=0
      - PGID=0
      - TZ=Asia/Shanghai
      - VERSION=docker
      - PLEX_CLAIM=##plex密钥##
      - NVIDIA_VISIBLE_DEVICES=all
      - NVIDIA_DRIVER_CAPABILITIES=all

volumes:
      - /mnt/video03/plex/video/anime:/anime
      - /mnt/video03/plex/config:/config
      - /mnt/video03/plex/streaming/ltab:/ltab
      - /mnt/video03/plex/video/movie:/movie
      - /mnt/video03/plex/streaming/music:/music
      - /mnt/video03/plex/transcode:/transcode
      - /mnt/video03/plex/video/tv:/tv
    restart: unless-stopped

后台启动

docker-compose up -d

停止并删除容器

docker-compose down

docker19 之后容器默认支持显卡驱动

docker run -d \
  --name=plex \
  --gpus all \
  --net=host \
  -e PLEX_UID=0 \
  -e PLEX_GID=0 \
  -e TZ=Asia/Shanghai \
  -e VERSION=docker \
  -e NVIDIA_VISIBLE_DEVICES=all \
  -e NVIDIA_DRIVER_CAPABILITIES=all \
  -e PLEX_CLAIM=claim-S_mzLQfFXfyy-KL-sS-a \
  -v /mnt/video03/plex/config:/config \
  -v /mnt/video03/plex/video/anime:/anime \
  -v /mnt/video03/plex/video/movie:/movie \
  -v /mnt/video03/plex/video/tv:/tv \
  -v /mnt/video03/plex/streaming/ltab:/ltab \
  -v /mnt/video03/plex/streaming/music:/music \
  -v /mnt/video03/plex/transcode:/transcode \
  --restart unless-stopped \
  plexinc/pms-docker:1.32.6.7557-1cf77d501

参考文献:

Plex transcoding with Docker – NVIDIA GPU : https://tizutech.com/plex-transcoding-with-docker-nvidia-gpu/

Installing the NVIDIA Container Toolkit : https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html

docker plex docker plex nvidia: https://blog.51cto.com/u_16099186/6501823