How To Run Plex Media Server in Docker Containers

Posted on 123 views

A media server is a computer system for storing digital media such as videos, images, and audio files. These files can be accessed and shared via the internet. There are several media servers such as; Subsonic, Emby, Madsonic, Gerbera, Universal Media Server, LibreELEC, Red5 OSMC, Kodi, Tvmobili, OpenFlixr, Jellyfin e.t.c.

Plex media server is a powerful full-featured server that allows one to stream media over the internet via compatible devices. Plex can be installed on Linux, macOS, Windows e.t.c. Plex has a simple interface and it organizes the data in beautiful libraries that make it easy for one to access them.

The features and benefits associated with Plex are:

  • Allows you to easily pick and choose what to share.
  • Supports cloud sync.
  • Offers the parental control functionality.
  • Supports encrypted connections with multiple user accounts.
  • Supports flinging of video from one device to another.
  • Has a media optimizer for Plex Media Player.
  • Supports audio fingerprinting and automatic photo-tagging.
  • Supports mobile sync which offers offline access to your media files.

This guide describes how to run Plex Media Server in Docker Containers.

Setup Pre-requisites

Update your system and install the required packages using the commands:

## On RHEL/CentOS/RockyLinux 8
sudo yum update
sudo yum install curl vim

## On Debian/Ubuntu
sudo apt update && sudo apt upgrade
sudo apt install curl vim

## On Fedora
sudo dnf update
sudo dnf -y install curl vim

Step 1 – Install Docker and Docker Compose

Before you proceed with this guide, you need Docker installed on your system. It can be installed using the dedicated guide below:

Once installed, ensure that the Docker Engine is started.

sudo systemctl start docker && sudo systemctl enable docker

Also, add your user account to the Docker group.

sudo usermod -aG docker $USER
newgrp docker

You can also install Docker Compose if you wish to run Plex from the Docker-Compose YAML file. Installing Docker Compose can be accomplished with the aid of the guide below:

Step 2 – Create a Persistent Volume for Plex

For the Plex data to persist, you need to create/mount the volumes on your system. There are several volumes required. Create the volumes as below.

sudo mkdir /plex
sudo mkdir /plex/database,transcode,media

On Rhel-based systems, you need to set SELinux in permissive mode for these paths to be accessible.

sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

Step 3 – Run Plex Media Server in Docker Containers

This guide provides two ways how to run the Plex Media Server in Docker Containers i.e directly with docker and using Docker-compose. With these methods, you can use 3 networking types:

  • Bridge – This is the default networking, it creates an entirely new network within the host and runs containers within it.
  • Host – This networking uses the IP address of the host running docker such that a container’s networking appears to be the host rather than separate.
  • macvlan – networking creates a new virtual computer on the network which is the container.

Setting up Plex using host and macvlan networking is easier and requires fewer workarounds. The docker files will be as below.

  • For Macvlan Networking

If using Macvlan Networking run the commands below:

docker run \
  -d \
  --name plex \
  --network=physical \
  --ip= \
  -e TZ="" \
  -e PLEX_CLAIM="" \
  -h  \
  -v /plex/database:/config \
  -v /plex/transcode:/transcode \
  -v /plex/media:/data \
  plexinc/pms-docker
  • For Host Networking
docker run \
  -d \
  --name plex \
  --network=host \
  -e TZ="" \
  -e PLEX_CLAIM="" \
  -v /plex/database:/config \
  -v /plex/transcode:/transcode \
  -v /plex/media:/data \
  plexinc/pms-docker

For this guide, I will demonstrate how to run Plex using the bridge(default) networking. Here several ports are exposed.

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="Africa/Nairobi" \
  -e PLEX_CLAIM="claim-ey6ekAqeQjosd1P" \
  -e ADVERTISE_IP="http://192.168.205.4:32400/" \
  -h plexserver.example.com \
  -v /plex/database:/config \
  -v /plex/transcode:/transcode \
  -v /plex/media:/data \
  plexinc/pms-docker

In the above command, obtain the PLEX_CLAIM using the URL https://www.plex.tv/claim. If this token is not provided, you cannot automatically log in to Plex.

Alternatively, you can use Docker Compose to run the Plex container with bridged networking as below.

Create a docker-compose.yml file

vim docker-compose.yml

In the file, add the below lines, replacing appropriately

version: '2'
services:
  plex:
    container_name: plex
    image: plexinc/pms-docker
    restart: unless-stopped
    ports:
      - 32400:32400/tcp
      - 3005:3005/tcp
      - 8324:8324/tcp
      - 32469:32469/tcp
      - 1900:1900/udp
      - 32410:32410/udp
      - 32412:32412/udp
      - 32413:32413/udp
      - 32414:32414/udp
    environment:
      - TZ=Africa/Nairobi
      - PLEX_CLAIM=claim-ey6ekAqeQjosd1P
      - ADVERTISE_IP=http://192.168.205.4:32400/
    hostname: plexserver.example.com
    volumes:
      - /plex/database:/config
      - /plex/transcode:/transcode
      - /plex/media:/data

You can run the container with docker-compose using the command:

docker-compose up -d

Once the container has started, view the status as below.

$ docker ps
CONTAINER ID   IMAGE                COMMAND   CREATED         STATUS                            PORTS                                                                                                                                                                                                                                                                                                                                                 NAMES
baf1e1a3b806   plexinc/pms-docker   "/init"   5 seconds ago   Up 2 seconds (health: starting)   0.0.0.0:3005->3005/tcp, :::3005->3005/tcp, 0.0.0.0:8324->8324/tcp, :::8324->8324/tcp, 0.0.0.0:1900->1900/udp, :::1900->1900/udp, 0.0.0.0:32410->32410/udp, :::32410->32410/udp, 0.0.0.0:32400->32400/tcp, :::32400->32400/tcp, 0.0.0.0:32412-32414->32412-32414/udp, :::32412-32414->32412-32414/udp, 0.0.0.0:32469->32469/tcp, :::32469->32469/tcp   plex

Step 4 – Access the Plex Web UI

AT this point, Plex is running with the Web accessible via the set URL http://IP_address:32400

How-To-Run-Plex-Media-Server-in-Docker-Containers

The Plex UI will load with the Plex Claim automatically loaded for the account set, proceed, and sign in to the dashboard.

How-To-Run-Plex-Media-Server-in-Docker-Containers-1-1024x543

On this dashboard, you can watch live TV, movies, shows, podcasts, listen to music, and add your media. Live Tv can be watched y selecting the desired channel.

How-To-Run-Plex-Media-Server-in-Docker-Containers-2-1024x743

Watch online movies and shows:

How-To-Run-Plex-Media-Server-in-Docker-Containers-3-1024x574

You can as well add media to Plex

How-To-Run-Plex-Media-Server-in-Docker-Containers-4-1

Media can be added to the server as below.

How-To-Run-Plex-Media-Server-in-Docker-Containers-5-1024x610

To make settings to Plex, navigate to the settings tab and make the desired settings.

How-To-Run-Plex-Media-Server-in-Docker-Containers-6-1024x736

Step 5 – Manage the Plex container.

The Plex container can be managed as below.

##To stop
docker stop plex

##To start
docker start plex

The container can also be managed as a system service by creating a service file for it as below:

sudo vim /etc/systemd/system/plex-container.service

In the created file, add the lines below.

[Unit]
Description=Plex container

[Service]
Restart=always
ExecStart=/usr/bin/docker start -a plex
ExecStop=/usr/bin/docker stop -t 2 plex

[Install]
WantedBy=local.target

Save the file and reload the system daemon.

sudo systemctl daemon-reload

Now start and enable Plex to run automatically on boot.

sudo systemctl start plex-container.service
sudo systemctl enable plex-container.service

Check the status of the service.

$ systemctl status plex-container.service
 plex-container.service - Plex container
   Loaded: loaded (/etc/systemd/system/plex-container.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-03-09 10:42:24 EST; 10s ago
 Main PID: 59416 (docker)
    Tasks: 8 (limit: 36438)
   Memory: 17.3M
   CGroup: /system.slice/plex-container.service
           └─59416 /usr/bin/docker start -a plex

Mar 09 10:42:24 localhost.localdomain systemd[1]: Started Plex container.

That is it!

This is the end of this guide on how to run Plex Media Server in Docker Containers. I hope this was significant to you.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.