Plex Dockerized

Hello TWiT Community!

Over on another thread we were having some fun talking about out Plex setups. @knewman asked if dockerized Plex had the ability to have GPU acceleration, and rather than hijack the tread with a random squirrel, I decided to have some fun with the new “Maker” tag that @Leo made. So, below is a simple guide on how to setup Plex dockerized and a few extra tips to help with GPU acceleration.

Most should know about Plex by now, and how handy it is to keep your media organized and accessible. Lately, I have been enjoying Docker and the ability to run multiple services on my home server without having to worry about dependency hell between services that don’t play nice together. Listed below is the growing list of all that I run.

Security

Before I get into the nitty-gritty. I want to make a note about security. All of your services need to be behind a firewall. No DMZs and only open the ports that you must. Docker may run on your computer, but the services are sandboxed (in a way) and a DMZ would open your server to the world. If you are going to run this on linux, I recommend Fail2Ban on every install so as to block basic ssh attacks. LetsEncrypt is a good way to keep your exposed sites secure, too.

Base Setup

My home lab has a computer running FreeNAS and an HP running Debian Linux. The FreeNAS computer is serving an NFS that is mounted by the HP that has the free ram and processor for everything to play nicely. A setup can be more complex than mine, or as simple as running on one computer. The TWiT Community is diverse and has plenty that would have network accessible storage. As such, I’m going to link to the base setup according to Plex, here, but I will show how to setup using Docker Compose & NFS (for those with really, really large media folders.

First, you will, of course, need Docker. I also like to use Docker Compose, as it makes multiple container management rather easy.

If using an NFS, you do not need to have it mounted on your system, as the docker-compose.yml file will tell Docker how to mount the NFS.

Plese Note: I’m a Linux user and running Plex in a docker on Windows is not recommended by Plex.

Configuration

When everything is ready, you will need to be root user on Linux, go home and make a folder named plex. Then go into your new working directory.

cd ~/
mkdir plex
cd plex

Now inside of the main directory for this Docker Compose instance, you will need to make the Docker Compose YAML file. This file will tell docker what to get and how to handle everything.

Create your docker-compose.yml file with a command line editor.

nano docker-compose.yml

Paste the contents below:

version: '3.6'

volumes:
  media:
    driver: local
    driver_opts:
      type: nfs
      o: addr=IP_OF_NFS_SERVER
      device: ":/mnt/driveName/mediaFolder/"

services:
  web:
    image: 'plexinc/pms-docker'
    container_name: plex
    network_mode: "host"
    restart: always
    environment:
      TZ: "America/New York"
      PLEX_CLAIM: "ThisIsToBeYourSuperSecretClaimCodeThatExpiresIn4MinutesAndIsPutInLast"
    volumes:
      - /root/plex/config:/config
      - /root/plex/temp:/transcode
      - media:/data

With the contents added to the file, you will want to make sure to edit the following before saving & exiting.

  • TZ: If not on EST. Others include America/Chicago (for Central) and America/Chihuahua (for Mountain)
  • IP address of the NFS server
  • NFS share folder that is being mounted
  • Your personal Plex claim number that can be found by visiting Claim | Plex
    • This claim number expires in 4 minutes, so do this right before saving and exiting
    • You may need to change this if you have issues when starting your container.
  • Note on Volumes:
    • If you are not using NFS you can simply delete the entire volumes: section and change the - media:/data to something like - /root/plex/media:/data.
    • Be sure to change /root/plex to the desired location of your files.
  • Plex does not recommend putting the transcoding or config folders on network storage as they need faster access than NFS can provide, in standard conditions.

After making all of the needed changes, save and exit your composer file and start your new media server! To do so in Nano you will want to type the below commands.

Ctrl+x
y
Enter

Run your server with the below command. The -d is used to tell docker to run in the background. If you are having issues, just remove the -d and see what you are left with. Ctrl-c will exit the container if you are watching the logs, hence pushing to the background.

docker-compose up -d

If everything started, you can now enjoy your media anywhere!

Hardware Acceleration

I do not have a graphics card in my setup as I know all of the devices that will be streaming from my server and have Plex set to auto-convert everything to the most optimal format for my devices. However, if you don’t want to bother with that, or just want to ensure the fastest conversion times, you will need to turn on hardware acceleration.

Doing so is easy and can be achieved by adding a devices: section under the web: service in the docker compose, like below.

    environment:
      TZ: "America/New York"
      PLEX_CLAIM: "ThisIsToBeYourSuperSecretClaimCodeThatExpiresIn4MinutesAndIsPutInLast"
    devices:
      - /dev/dri:/dev/dri
    volumes:

Note: Indentation matters in YAML files. Make sure things line up right.

Updates

We all want the latest & greatest. This is why I like Docker/containers. Updating is (usually) really easy when everything is containerized. Just run the below commands and Plex will upgrade to the latest version!

docker-compose pull
docker-compose down -v
docker-compose up -d

Closing

This is my first full tutorial for anyone other than myself. Please let me know if you have questions or issues. I’ll try my best to edit this and respond quickly.

Enjoy!

Extra

After you have everything running, be sure to search for TWiT and add to your podcasts!

4 Likes

dude epic post! was expecting a simple yes/no, instead I’ve got a weekend project now haha

1 Like

Nice one. I am just using a vm for plex.

2 Likes

Nice guide. Thanks for posting it on TWiT.social, too. That’s where I first found the link.

2 Likes