Plex - martikainen87/Home-Automation GitHub Wiki

Plex Media Server for docker, will remove all needs to hustle with updates.

Adding Plex to your docker environment

The image can be found here Plex @ Docker hub

sudo nano /Docker/docker-compose.yml

And add the docker compose string

version: '2'
services:
  plex:
    container_name: plex
    restart: unless-stopped
    environment:
      - TZ=${TIMEZONE}
      - PLEX_CLAIM=${CLAIM_CODE}
      - PLEX_UID=1000
      - PLEX_GID=1000
    privileged: true
    network_mode: host
    volumes:
      - ./Plex:/config
      - ./Plex/transcode:/transcode
      - /share/Media:/data
    build:
      context: https://github.com/Pretagonist/plex-rar2fs-docker.git

then add this to your .env file

sudo nano /Docker/.env
# Global envs
TIMEZONE=Europe/Stockholm
# Plex
CLAIM_CODE=InsertClaimCodeHere

Configuring Plex

  • Open your browser and go to http://yourip:32400/web
  • Logon to your plex account
  • Add your media libraries
  • Select advanced settings for choice of ratings, info etc.
  • Go watch a movie!

Migrating Plex from ubuntu to your docker container

Move Plex to new server

Data locations

Since probably many of you already have Plex running and want to move it to docker, here's a way to do it without loosing your settings, watched items etc.

exporting data regular install

The plex data on ubuntu is located at /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/

Lets start with sending everything to a rar archive to not waste time on moving thousands of cache files one at the time.

cd /var/lib/plexmediaserver/Library/Application Support
tar cvzf plex.tar.gz /home/pi/share/PlexExport

Now we have a rar file with all the metadata from our current installation

exporting data from a previous Docker installation

Stop the plex container on the old server

docker stop plex

Create the directory on the new server

sudo mkdir /Docker/Plex

Run this command from the new server

Copy the files from the remote server to the new server

scp -r [email protected]:/Docker/Plex /Docker/Plex

Preparing Plex on Docker

Setup Plex in a container and start it, but dont login! Just let it create it's dependencies and shares that we specified. See the wiki for info Plex

Stop the container

docker stop plex

Extract the data

Copy the rar file to it's directory and extract it

sudo cp /share/PlexExport Docker/Plex/Config/Library/Application\ Support/
sudo tar -xzvf plex.tar.gz

It will take a couple of minutes but afterwards you should have a new folder in the "Application Support" folder called "Plex Media Server"

browse it and see that all folders have been migrated

 cd /Docker/Plex/Config/Library/Application\ Support/Plex\ Media\ Server/

And verify the files with `ls -color´

pi@DockerHost1:/Docker/Plex/Config/Library/Application Support/Plex Media Server$ ls -color
total 40
-rw------- 1 pi 1237 Jun 13 22:21 Preferences.xml
drwxr-xr-x 7 pi 4096 Jun 13 21:42 Plug-in Support
drwxr-xr-x 9 pi 4096 Jun 13 21:42 Plug-ins
-rw-r--r-- 1 pi    3 Jun 13 21:44 plexmediaserver.pid
drwxr-xr-x 4 pi 4096 Jun 13 21:42 Metadata
drwxr-xr-x 3 pi 4096 Jun 13 21:42 Media
drwxr-xr-x 3 pi 4096 Jun 13 22:13 Logs
drwxr-xr-x 4 pi 4096 Jun 13 21:42 Crash Reports
drwxr-xr-x 4 pi 4096 Jun 13 21:42 Codecs
drwxr-xr-x 5 pi 4096 Jun 13 22:25 Cache
pi@DockerHost1:/Docker/Plex/Config/Library/Application Support/Plex Media Server$

then remove the rar file

sudo rm /Docker/Plex/Config/Library/Application Support/plex.tar.gz

now we need to start the container and give plex access to the files

docker start plex

docker exec -it plex /bin/bash

chown -R abc:abc  /config/Library/Application\ Support/Plex\ Media\ Server/

It might not be needed, but shutdown your old plex server before continuing.

Restart the docker container

docker restart plex

Open your browser and go to http://yourip:32400/web

Login to your plexaccount if needed, and if everything worked fine you should see your movies/series, but we need to update the path's to the series

Edit your libraries and remove the old path and make sure the new path is configured /data/movies and /data/tvshows

When everything is ready, go ahead and "Clean Bundle", empty the trash and Optimize the database (everything found on the three dots next to the "libraries" choice in the left menu).

When it's finished restart plex and verify that you can watch the content, and check remote access if you're using it!

issues with migrating the entire library?

https://support.plex.tv/articles/201154527-move-viewstate-ratings-from-one-install-to-another/

Install the new server and run the startup wizard. Add your data folders and let it scan

The viewstate, watched/unwatched etc are stored in a separate database which is easy to migrate.

  • Stop both the old PLEX server and the new one

Go to the database folder on the old server

cd /Docker/Plex/Config/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/

Run the export command

echo ".dump metadata_item_settings" | sqlite3 com.plexapp.plugins.library.db | grep -v TABLE | grep -v INDEX > settings.sql

Use wincsp to copy the file to your new server, at the same location

Run the import command

cat settings.sql | sqlite3 com.plexapp.plugins.library.db

Start your server and hit "update library", "Update metadata" etc, and eventually it will load all states.