Guides - Note about Nvidia GPU passthrough into Docker /Portainer containers when using Proxmox --gpus | PlexGuide.com

Guides Note about Nvidia GPU passthrough into Docker /Portainer containers when using Proxmox --gpus

  • Stop using Chrome! Download the Brave Browser via >>> [Brave.com]
    It's a forked version of Chrome with native ad-blockers and Google's spyware stripped out! Download for Mac, Windows, Android, and Linux!
Welcome to the PlexGuide.com
Serving the Community since 2016!
Register Now

jjnz123

Citizen
Original poster
Donor
Apr 14, 2020
6
4
From what I have managed to find on the net, there is very little documentation in a single place around getting an Nvidia GPU to work in Docker containers when using Plexguide (and others).

The issue I ran into was that the new '--gpus' switchline is not compatible with Portainer, so the GPU could not be passed to the containers.
[See https://github.com/docker/compose/issues/6691 existing bug]

From the start:

Install drivers and patch
Once you have the GPU successfully passed through into the Linux VM, the next step is to install Nvidia drivers and patch.
Install all dependencies before installing drivers otherwise you will have issues -- sudo apt-get install build-essential gcc-multilib dkms
Now follow: https://github.com/keylase/nvidia-patch

Install Nvidia Container Toolkit
Once the GPU is installed on the host and tested using nvidia-smi install the toolkit:
Link here: https://github.com/NVIDIA/nvidia-docker

This allows all the docker containers to use the Nvidia GPU.
Test that a container can run nvidia-smi by running docker run --gpus all nvidia/cuda:10.0-base nvidia-smi.
You should get the same result as you did when running on the host.

Configure container to use --gpus all switch
Now this is the bit I am hoping someone will come along and say there is an easier way.
There is currently no way to get Portainer to use the --gpus switch as it doesn't yet exist in the Docker API that Portainer uses (Portainer doesn't use CLI).
So the only work around I have found is to convert the Portainer Plex container config to a Docker run command using a script file.

This is my script file (with omissions)
This container is set to self destruct if stopped. This ensures that it can't be started without running the --gpus switch which allows for GPU use.

EDIT: I run the container privileged so I can access SMB mounts on the host.

Code:
docker run \
-d \
--privileged \
--rm \
--gpus all \
--name plex \
-p 32400:32400/tcp \
-p 3005:3005/tcp \
-p 8324:8324/tcp \
-p 32469:32469/tcp \
-p 1900:1900/udp \
-p 32410:32410/udp \
-p 32412:32412/udp \
-p 32413:32413/udp \
-p 32414:32414/udp \
-e PLEX_UID=1000 \
-e PLEX_CLAIM="cxxxxx" \
-e ADVERTISE_IP="http://xxxx:32400, https://xxxxx:443" \
-e PLEX_GID=1000 \
-e PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
-e TERM=xterm \
-e LANG=C.UTF-8 \
-e LC_ALL=C.UTF-8 \
-e CHANGE_CONFIG_DIR_OWNERSHIP=true \
-e HOME=/config \
-e NVIDIA_VISIBLE_DEVICES=all \
-e NVIDIA_DRIVER_CAPABILITIES=compute,video,utility \
-l traefik.enable=true \
-l traefik.frontend.headers.SSLHost=xxxxx \
-l traefik.frontend.headers.SSLRedirect=true \
-l traefik.frontend.headers.STSIncludeSubdomains=true \
-l traefik.frontend.headers.STSPreload=true \
-l traefik.frontend.headers.STSSeconds=315360000 \
-l traefik.frontend.headers.browserXSSFilter=true \
-l traefik.frontend.headers.contentTypeNosniff=true \
-l traefik.frontend.headers.customResponseHeaders=X-Robots-Tag:noindex,nofollow,nosnippet,noarchive,notranslate,noimageindex \
-l traefik.frontend.headers.forceSTSHeader=true \
-l traefik.frontend.rule=Host:xxxxx,xxxxxx \
-l traefik.port=32400/tcp \
-v /opt/appdata/plex/database:/config \
-v /opt/transcodes:/transcode \
-v /mnt:/mnt \
-v /dev/shm:/ram_transcode \
-v /tmp:/tmp \
-v /etc/localtime:/etc/localtime \
--device=/dev/dri:/dev/dri \
--add-host=analytics.plex.tv:127.0.0.1 \
--add-host=metrics.plex.tv:127.0.0.1 \
plexinc/pms-docker
 
  • Like
Reactions: 2 users

Admin9705

Administrator
Project Manager
Donor
Jan 17, 2018
5,156
2,109
k will wiki this thing later also
 

jjnz123

Citizen
Original poster
Donor
Apr 14, 2020
6
4
This is my script file (with omissions)
This container is set to self destruct if stopped. This ensures that it can't be started without running the --gpus switch which allows for GPU use.
UPDATE 6/6/2020 I have removed --rm from the code below. I have tested the container by stopping and restarting, and the --GPUS command sticks. No need to destroy container if it stops. I have also added --restart=always to ensure container self restarts.

EDIT: I run the container privileged so I can access SMB mounts on the host.

Code:
docker run \
-d \
--restart=always \
--privileged \
--gpus all \
--name plex \
-p 32400:32400/tcp \
-p 3005:3005/tcp \
-p 8324:8324/tcp \
-p 32469:32469/tcp \
-p 1900:1900/udp \
-p 32410:32410/udp \
-p 32412:32412/udp \
-p 32413:32413/udp \
-p 32414:32414/udp \
-e PLEX_UID=1000 \
-e PLEX_CLAIM="cxxxxx" \
-e ADVERTISE_IP="http://xxxx:32400, https://xxxxx:443" \
-e PLEX_GID=1000 \
-e PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
-e TERM=xterm \
-e LANG=C.UTF-8 \
-e LC_ALL=C.UTF-8 \
-e CHANGE_CONFIG_DIR_OWNERSHIP=true \
-e HOME=/config \
-e NVIDIA_VISIBLE_DEVICES=all \
-e NVIDIA_DRIVER_CAPABILITIES=compute,video,utility \
-l traefik.enable=true \
-l traefik.frontend.headers.SSLHost=xxxxx \
-l traefik.frontend.headers.SSLRedirect=true \
-l traefik.frontend.headers.STSIncludeSubdomains=true \
-l traefik.frontend.headers.STSPreload=true \
-l traefik.frontend.headers.STSSeconds=315360000 \
-l traefik.frontend.headers.browserXSSFilter=true \
-l traefik.frontend.headers.contentTypeNosniff=true \
-l traefik.frontend.headers.customResponseHeaders=X-Robots-Tag:noindex,nofollow,nosnippet,noarchive,notranslate,noimageindex \
-l traefik.frontend.headers.forceSTSHeader=true \
-l traefik.frontend.rule=Host:xxxxx,xxxxxx \
-l traefik.port=32400/tcp \
-v /opt/appdata/plex/database:/config \
-v /opt/transcodes:/transcode \
-v /mnt:/mnt \
-v /dev/shm:/ram_transcode \
-v /tmp:/tmp \
-v /etc/localtime:/etc/localtime \
--device=/dev/dri:/dev/dri \
--add-host=analytics.plex.tv:127.0.0.1 \
--add-host=metrics.plex.tv:127.0.0.1 \
plexinc/pms-docker
 
  • Like
Reactions: 1 user

Admin9705

Administrator
Project Manager
Donor
Jan 17, 2018
5,156
2,109
ah nice, thanks!
 

Recommend NewsGroups

      Up To a 58% Discount!