TrueNAS + Plex on Linux with scripted installation

apwiggins

Dabbler
Joined
Dec 23, 2016
Messages
41
[Edit: Graciously moved into a new thread by ericloewe; original was a response to a thread on scripted Plex installs more generally on TrueNAS]

In the spirit of scripted Plex installs, we started running Plex on FreeNAS/TrueNAS about 5 years ago and ended up in a different place a few years later, so sharing a possible path for you to explore. The guys at linuxserver.io do a wonderful job of maintaining a set of docker containers for Plex and other apps. For our setup, TrueNAS serves up an NFS share for each media type. Separately, a Linux VM runs a couple of shell scripts that pull the docker containers for Plex and additional scripts in the same pattern for other containers/apps. To update the Plex container, just re-run update_plex.sh which will stop the running container, pull a new container and start the newest instance (~30 seconds). Now Plex is available from the Linux VM but consuming media from a TrueNAS NFS share. We ran Plex on FreeNAS/TrueNAS for a few years, but found updates had some issues from time-to-time. The docker container has been rock-steady in comparison and updates are super-easy.

The hardest part was the initial NFS share setup which sometimes required troubleshooting NFS on the TrueNAS side and NFS inside the plex container. Although the docker gurus at linuxserver.io recommend using NFS docker volumes, the following works for us on TrueNAS.

update_plex.sh (on a docker-enabled Linux VM; sudo not required if user is added to the 'docker' group)
#!/usr/bin/env bash
# maintains config on localhost at /home/docker/plex
NAS='192.168.xxx.xxx' #ip address
NAS_SERIES=/mnt/tank/series
NAS_MOVIES=/mnt/tank/movies
NAS_MUSIC=/mnt/tank/music
name=plex
image='ghcr.io/linuxserver/plex'

sh ./update.sh $name $image

echo "==> recreating plex"
sudo docker create \
--name=$name \
--net=host \
-e PUID=1000 \
-e PGID=1000 \
-e VERSION=docker \
-e UMASK_SET=022 `#optional` \
-e PLEX_CLAIM= `#optional` \
-v /home/docker/plex/library:/config \
--mount type=volume,dst=/tv,volume-driver=local,volume-opt=type=nfs,\"volume-opt=o=nfsvers=4,addr=${NAS}\",volume-opt=device=:${NAS_SERIES} \
--mount type=volume,dst=/movies,volume-driver=local,volume-opt=type=nfs,\"volume-opt=o=nfsvers=4,addr=${NAS}\",volume-opt=device=:${NAS_MOVIES} \
--mount type=volume,dst=/music,volume-driver=local,volume-opt=type=nfs,\"volume-opt=o=nfsvers=4,addr=${NAS}\",volume-opt=device=:${NAS_MUSIC} \
--restart unless-stopped \
$image

echo "==> restarting "$name
sudo docker start $name
update.sh (on a docker-enabled Linux VM)
#!/usr/bin/env bash

name=$1
image=$2

echo "==> stopping "$name
sudo docker stop $name
echo "==> removing old "$name" container"
sudo docker rm $name
echo "==> removing old images"
sudo docker image prune -f
echo "==> removing old volumes"
sudo docker volume rm `docker volume ls -q -f dangling=true`
echo "==> pulling new "$name" container"
sudo docker pull $image

A bit off-topic -- Initially, we ran a docker host using Clear Linux VM as a bhyve-based VM on TrueNAS directly, but more recently this Clear Linux VM has been shifted to run on a separate Proxmox hypervisor. Also, TrueNAS has been shifted to run on the Proxmox hypervisor as well with disks exposed directly to the TrueNAS VM on Proxmox and we're using TrueNAS mostly for file-sharing which it's fantastic at doing. Portainer has been added to manage the docker environment, but ssh'ing into the Clear Linux VM to run updates via shell scripts is more reliable than Portainer's internal container update.

Why Clear Linux as docker VM? It's cattle, not a pet. It's Intel's linux distro. It's fast. It auto-updates for security patches. Clear Linux Docker
 
Last edited:
Top