Converting Plex Linux Standalone to Docker Container

in STEMGeekslast month

Plex!

Take the Plunge

If you're a Plexaholic like I am, you've probably had some version of the same server around for quite some time. You know that migrating from one piece of hardware to another can be trying at times to get all of your data and metadata back in the right order. This may not be a problem for some of you forward-thinking types out there that stored your metadata on a NAS or SAN that is backed up, but even that can be difficult to get working again with a bare-metal rig. In this (hopefully) helpful guide, I will attempt to alleviate some of the initial install woes by helping you migrate your Plex installation to Docker.

Requirements

  • A Linux Computer (I'm running Ubuntu on mine so the commands in this guide will reflect Debian and Ubuntu-based distributions)
  • Portainer Community Edition - Free and Open (Located Here)
  • Knowledge of Docker, Dockerbuild/Docker Compose, and the Linux CLI environment.

Setup

This guide assumes you have already installed and configured your Linux server. You should also have a copy of your Plex metadata handy (this can be on the server already or in a backup connected to the server). As stated above, we are using Ubuntu in this guide so the commands will vary from distribution to distribution. Since you're already this far, let's go ahead and get Portainer installed.

To do this, we will need to get the file onto our server. Let's grab docker and Portainer:

sudo apt install docker docker.io docker-compose -y
sudo docker volume create portainer_data
sudo docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce

What are we doing with those commands? The first command installs the base docker installation that allows for us to utilize Portainer and the upcoming installation of the Plex container. The second and third create the docker storage volume for Portainer and installs the actual web application. We are port forwarding ports 8000 and 9000 from our docker.sock to our server's networking stack. This will allow us to access the portainer web app from our web browser and start the installation process for our Plex container.

Installation and Configuration of Plex Docker Image

(NOTE: This guide assumes your current Plex metadata is located at /var/lib/plexmediaserver and your media is stored at /mnt/media. If your information is located elsewhere, please modify the scripts below to match your setup.)

Open your web browser of choice and aim it at http://localhost:9000 or http://IP_OF_SERVER:9000 to get to Portainer. The first time you visit, you will be asked to create an administrator account. Change the username if you'd like and enter your unique password. On the next page, select Docker. In the information section, it asks us to enrue that we used -v "/var/run/docker.sock:/var/run/docker.sock" which we did in our command above, so you can ignore that area and click Connect. Next, we will click on the local Endpoint, this will take you to the dashboard.

Back in our Linux terminal, we are going to do the actual Plex Docker installation and configuration. Portainer will be used to assist in updates, reboots, and accessing Plex from a command line. The two choices are the LinuxServer/plex container through docker-compose or the official Plex Dockerfile method. I have added both below with the edits needed to get your current server metadata and media instantly connected to your new Dockerized Plex installation.

You will need to create a docker-compose.yml file using your favorite CLI text editor, I'll use nano for ease of use. You can locate your Plex claim token before running the compose file. This is not required but will make things a bit speedier now and in the future for updates. You will also need to set up your Time Zone in the Dockerbuild script.

Copy the following into the newly created docker-compose.yml:

---
version: "2.1"
services:
  plex:
    image: ghcr.io/linuxserver/plex
    container_name: plex
    network_mode: host
    environment:
      - PUID=1000
      - PGID=1000
      - VERSION=docker
      - PLEX_CLAIM= #optional
    volumes:
      - /var/lib/plexmediaserver:/config
      - /mnt/media:/data/media
      - /tmp/transcode:/transcode
    restart: unless-stopped

Once you've created this file and made your changes, run the following command to start the installation:

sudo docker-compose up plex

After the installation is finished, you will need to kill the running instance in your terminal. This can be done with a CTRL+C or CTRL+Z.

If you'd prefer the official Plex container (more up-to-date than LinuxServer.io when updates are pushed), you can run the following Dockerbuild commands directly in the terminal.

sudo docker pull plexinc/pms-docker
sudo docker run -d –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 TZ=“YOUR-TIME-ZONE”
-e PLEX_CLAIM="#YOURCLAIMTOKEN"
-e ADVERTISE_IP=“http://YOUR_SERVER_IP:32400/”
-h YOUR_SERVER_IP
-v /var/lib/plexmediaserver:/config
-v /mnt/media:/data/media
-v /tmp/transcode:/transcode
plexinc/pms-docker

Once your Plex Docker Container of choice is installed, head back over to Portainer (http://YOUR_SERVER_IP:9000, click the local Endpoint, click Containers) and you'll find your new container stopped and ready to be started. Once you click on the specific container, we can clickStartin the actions section to start our container. You'll need to stop your other Plex instance on the server if it's running as to not cause port conflicts. This can be done simply by running sudo systemctl stop plexmediaserver in the Linux terminal. Once that's done, Start our container.

Enjoy!

If your metadata is on the server at /var/lib/plexmediaserver, you should be able to point your web browser at http://YOUR_SERVER_IP:32400/web. You will be greeted by a familiar-looking Plex installation and think to yourself, "Did I install this correctly? Why does it look the same!?" but that's exactly what we wanted! Everything to look identical without losing any ratings, custom artwork, or any other custom modifications. You may have to sign in once, but everything else should be identical to your bare-metal installation!


Sippy's HIVE Links:

Posted with STEMGeeks

Sort:  

Congratulations @sippycup540! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You received more than 100 upvotes.
Your next target is to reach 200 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

Feedback from the April 1st Hive Power Up Day