Installing Plex On A Raspberry PI With Docker and Ubuntu

In this tutorial, we are going to look at how to install Plex Media Server inside a Docker container on a Raspberry PI4 running Ubuntu Linux. I am attaching an SSD to the Raspberry PI4 and mounting it to use it as storage for my media files. So first thing’s first…

What is Plex Media Server?

Plex is a free and Opensource Media Streaming Server that you can host in your home or local network to steam your media to your smart tv or through your browser. If you have a collection of tv shows and movies and you are looking to stream them over your local network then you can utilize plex.

Setup Docker and Docker-Compose

Follow these steps to install docker and docker-compose on either a Raspberry PI4 or Intel System.

Mount SSD

Next, we are going to look for our connected SSD. My SSD is connected via USB mount, I am using a type of rackmount kit for the raspberry pi, you can check it out on Amazon if you want to get one for yourself. Once the SSD is plugged in you should check if the Operating System is detecting it:

sudo fdisk -l

The output should be similar to the output below:

Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 * 2048 526335 524288 256M c W95 FAT32 (LBA)
/dev/mmcblk0p2 526336 249737182 249210847 118.9G 83 Linux


Disk /dev/sda: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: 500G2B0A-00SM50
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: gpt
Disk identifier: 25A4E001-952D-45E9-907A-4A3447A2373F

Device Start End Sectors Size Type
/dev/sda1 34 32767 32734 16M Microsoft reserved
/dev/sda2 32768 976771071 976738304 465.8G Microsoft basic data

Once you can see and confirm that the SSD is connected, you have to create a directory and mount the SSD to it with the following commands:

Create the directory:

mkdir /media/plex

Mount the ssd partition to the plex directory:

mount /dev/sda2 /media/plex

The next step is to check if the SSD partition is mounted correctly:

mount | grep sda2

The output should be similar:

/dev/sda2 on /media/plex type fuseblk (rw,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096)

If you ever want to unmount the SSD you can use the unmount command but for this specific use case, we want to permanently mount the SSD on startup. In the next step we are going to look for the UUID of the device as it never changes whereas your partition id can always change as you unmount or mount new USB devices. Let’s run the following command to get the UUID:

ls -l /dev/disk/by-uuid

Once you get the UUID output you have to copy the device UUID and add it to the fstab config file:

sudo nano /etc/fstab

Add the following line of code to the fstab config file and save it:

UUID={your-uuid} /media/plex ntfs-3g auto,users,uid=1001,gid=1001 0 0

Once completed and saved the next step is to reboot the plex pi(Raspberry PI4 Plex Media Server) to see if it automounts the SSD at startup. Run the following command once the reboot completes:

mount | grep sda2

Install Plex Media Server with Docker

Once confirmed that the SSD partition auto mounts after reboot it is time to compile the docker-compose file to deploy plex inside a docker container. Head of to LinuxServerPlex and copy the docker-compose script and edit it accordingly.

Run the following commands to the PUID and PGID:

id $USER

Under volumes add the directories of your media directories and add the config directory which should be a local directory on your OS partition due to mounted disks has some sqlite issues.

Create a docker-compose file and add the below script after you edit it according to your system environment:

nano docker-compose.yml

Copy the below YAML script to docker-compose.yml

version: "2"
services:
plex:
image: linuxserver/plex
container_name: plex
network_mode: host
environment:
- PUID=1001 
- PGID=1001 
- VERSION=docker
volumes:
- /docker/plex/library:/config
- /media/plex/tvseries:/tv
- /media/plex/movies:/movies
restart: always

The next step is to run docker-compose up to deploy our Plex Media container:

docker-compose up -d

Once the deployment is complete run the following command to ensure that the plex container is running:

docker ps

Output:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d7d0e3626f18 michaelmiklis/rpi-monitor:latest "/usr/bin/entry.sh /…" 4 days ago Up 14 hours 0.0.0.0:8888->8888/tcp, :::8888->8888/tcp rpi-monitor
457cc90cd12a lscr.io/linuxserver/plex "/init" 2 weeks ago Up 14 hours plex
d05fb20b9a26 portainer/agent:latest "./agent" 5 weeks ago Up 14 hours 0.0.0.0:9001->9001/tcp, :::9001->9001/tcp portainer_agent

Once confirmed that the container is running you can head to your browser and open http://<your-ip>:32400/web and start setting up your plex server.

Liked it? Take a second to support Chad Crouch on Patreon!

Chad Crouch

Chad is a Software/DevOps Engineer with exposure and experience in various technologies and enterprise ICT environments. He has a huge passion for Technologies, specifically Linux and Open Source Software. If you enjoy our articles please support us and make a small contribution: Buy Us A Coffee