Table of Contents

Introduction

When you begin to research “how” to stream your media collection to your devices, you will find one simple conclusion is unavoidable: the most common way to stream media to your devices is Plex.

Plex is everywhere, and it is used ALL the time !!!

Installing Plex

In the below sections, you will find the commands for creating a docker container of the LinuxServer.io1 Plex Media Server.2 Thanks to the introduction of docker manifest you do not need to worry about the architecture of your docker host (e.g. amd64 vs. arm), just execute the following commands on your docker host.3

Before looking at the command, it is useful to clarify and briefly explain some of the options and variables passed to the docker create4 command:

  • --net=host - Shares host networking with container, required.
  • -v /config - Plex library location. This can grow very large, 50gb+ is likely for a large collection.
  • -v /data/xyz - Media goes here. Add as many as needed e.g. /data/movies, /data/tv, etc.
  • -e VERSION=latest - Set whether to update plex or not - see Setting up application section.
  • -e PGID= for for GroupID - see below for explanation
  • -e PUID= for for UserID - see below for explanation
  • -e TZ - for timezone information eg Europe/London, Asia/Shanghai, etc

Sometimes when using data volumes (-v flags) permissions issues can arise between the host OS and the container. This can be avoided by specifying the user PUID and group PGID. Ensure the data volume directory on the host is owned by the same user you specify and it will “just work.”

To find yours use id $USER as below:

$ id $USER
    uid=1001(dockeruser) gid=1001(dockergroup) groups=1001(dockergroup)

So from this information, we can see that uid=1001, and gid=1001. Hence when we run the docker create command below, we will set PUID=1001 and PGID=1001.

What follows is the docker command for pulling the LinuxServer.io1 docker image and creating a container to run the Plex Media Server.

docker create \
--name=plex \
--net=host \
-e PUID=<UID> -e PGID=<GID> \
-v </path/to/library>:/config \
-v <path/to/tvseries>:/data/tvshows \
-v </path/to/movies>:/data/movies \
linuxserver/plex

NOTE: As an example for the Raspberry Pi, we will likely want to consider using an external drive to store the Movies and the Plex configuration directories. This is due to the more robust I/O capabilities of a Hard Disk Drive vs. a micro SD card.5 More information on the formatting process of the drive can be found in another post6 devoted to reformatting a hard disk drive in ext4.

Once we have our external drive ready (in this case mounted to /mnt/PIDRIVE), we can create the container as follows:

docker create \
--name=plex \
--net=host \
-e VERSION=latest \
-e PUID=1001 \
-e PGID=1001 \
-e TZ='America/Chicago' \
-v /mnt/PIDRIVE/plex_config:/config \
-v /mnt/PIDRIVE/movies:/data/movies \
linuxserver/plex

Notice here that we have PUID=1001 and PGID=1001, TZ=America/Chicago, /mnt/PIDRIVE/plex_config:/config, and /mnt/PIDRIVE/plex_config:/data/movies. Basically, the results of the id $USER showed uid=1001 and gid=1001, hence the user set PUID=1001 and PGID=1001, the user set the timezone to America/Chicago, and has created their Plex config dir on their external drive at /mnt/PIDRIVE/plex_config with all of their media on the same external drive at /mnt/DATADRIVE/movies.

Running Plex

Now that our docker container has been created, we can simply run it with:

$ docker start plex

This will start the container, and run it as a daemon (i.e. in the background).

Accessing Plex

Now that the docker container for Plex has been built and is running on your server, you can access it. The most basic way to access the Plex application is through the WebUI by navigating in your browser to the following URL:

HOST_IP_ADDRESS:32400/web

This could be something like:

raspberrypi.local:32400/web

Or maybe:

gnosis.local:32400/web

Or simply use the local IP address of the host:

192.168.10.20:32400/web

Initial Configuration

Without going into too much detail, the initial setup will require two parts:

  • 1: You will be prompted to login or create a Plex account
  • 2: You must select where the media is stored that will be used with Plex

Basically after creating a Plex account, or logging in to an existing account just make sure to add a Movie library, and use the path to /data/movies as the path to where the media are located. More detailed information can be found in the official Plex post7

Advanced Configurations

In this section we will discuss the various advanced features of both Plex, and the host operating system for configuring your system for various needs (e.g. backing up your media, downloading subtitles automatically, etc …)

Backing Up Media and Data

One of the best ways to backup any Unix-like system is through a utility known as cron. While we will not discuss in detail how to edit a crontab, we will refer you to a previous post on the subject.

Instead we will show you an example of a crontab entry that will backup the external drive containing all your media files and Plex data to another external drive:

$ sudo crontab -e
...
...
...
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,$
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

# backup PIDRIVE to PIBACKUP
01 01 * * * sudo rsync -havP /mnt/PIDRIVE/ /mnt/PIBACKUP/

What the above example shows, is that the rsync command will run with super user privileges at 01:01 am or one minute past one in the morning (or late at night if you are not a morning person). When it runs it will backup the contents of the drive at /mnt/PIDRIVE to /mnt/PIBACKUP. This will ensure that every night at one minute past one in the morning, the drive with all your Plex data and media, will be copied to the drive at /mnt/PIBACKUP

References