April 3, 2020

Docker Plex Part 1

Getting started!

Installing Ubuntu, Docker, Docker-Compose and Plex

I started helping out a friend with trying to set up his own Plex server.  He wanted to try and host his own media after experiencing some buffering issues trying to stream from my server during the whole COVID pandemic.  Him being still pretty new to the Linux world, I started walking him through some simple Linux 101 basics and we setup an Ubuntu server running Docker with Docker-compose and a container running linuxserver/plex.

Most of those steps were simple all pretty simple and he followed through the tutorial laid out this this YouTube video (start at around 7:42).  

Ubuntu Docker and Compose

Essentially the steps we took out from the video were:

  • Install Ubuntu 18.04 as your OS
    + You can find the download for Ubuntu 18.04 here
    • For instructions on how to install the OS, you can follow the guide provided by Ubuntu here
  • Install Docker
    • Instructions for installing Docker on Ubuntu can be found here
    • NOTE: To make things easier down the road, you want to follow the instructions to also add your user account to the docker group and have docker run at startup/on reboot
    • To add your user to the docker group follow these instructions
    • To get docker to run at start up follow these instructions
  • Lastly install docker-compose
    • Instructions for installing docker-compose can be found here
    • NOTE make sure to select Linux and follow the Linux instructions.


Once we got Ubuntu, Docker, and Docker-Compose installed we had to mount his HDD where we will store all his media.  Following the instruction the guy provided in his video is pretty straight forward.  You can skip to that part in the video here.  Here's a quick breakdown of what he does:

  • Create the folder where you want to mount your Plex media drive
    • mkdir /media
  • Once the folder is created we want to identify your HDD so we can mount it to that /media folder
  • Running df -h will give you a list of all filesystems on your machine
  • You should get an output that looks something like this:
Filesystem       Size  Used   Avail Use% Mounted on
/dev/sdc         4.9T  0      4.9T  0%  
tmpfs            12G   152K   12G   1%   /dev/shm
tmpfs            2.4G  80K    2.4G  1%   /run/user/1000
  • You should be able to identify your HDD based on it's size
  • In our case ours is the /dev/sdc 4.9T there on the second line
  • From here we just need to mount that drive to the folder we created
    • mount /dev/sdc /media
  • Finally we want to make sure this mount persists on reboot so we want to add it to our fstab
  • First let's make sure we got the right filesystem
    • mount | grep "^/dev"
    • This should return all the currently mounted drives starting with the /dev prefix
    • Find your /dev/sdc drive mounted to /media
    • You should see a type in the results, in our case ext4, jot that down
  • Next we add this to the fstab
    • sudo nano fstab
    • Then add this line to the bottom of that file
    • /dev/sdc /media ext4 defaults 0 0

Docker Compose Yaml

Now that the /media folder is created we need to spin up the docker container.  We went out to Docker hub's linuxserver/plex and copied down their example docker-compose file.  To make things simple, create a directory to store our compose file and saved the yaml file in there.

mkdir -p /media/plex/

Then we copied/saved the docker-compose.yml file in that directory.

We made a few edits to the file to line up with our folder structure and our compose file now looks like this:

version: '2'
    image: linuxserver/plex
    container_name: plex
    network_mode: host
      - PUID=1000
      - PGID=1000
      - VERSION=docker
      - UMASK_SET=022 
      - PLEX_CLAIM= 
      - '32400:32400'
      - /media/plex/config:/config
      - /media/tv:/tv
      - /media/movies:/movies
    restart: unless-stopped  

There were a few things that we had to go over that doesn't get fully explained in his video, but probably because the YouTuber expects the viewer to already have some Docker experience.  The volume mounting and directories being the main hiccup.
In the docker-compose.yaml file we had to change the volumes mounted to the actual directory where the Movies and Shows were going to be hosted.  

      - /media/plex/config:/config
      - /media/tv:/tv
      - /media/movies:/movies

What you're seeing above is the mounting of the local path to a path inside the Docker container.  So from within the Ubuntu host, you can navigate directly to /media/movies and see all the movies you placed in there.  But if you were inside the container the /media/movies doesn't exist.  That's because inside the container all those movies actually live in the folder /movies.  So when you get to the set-up part of Plex and you're asked for a folder to import, you want to import from /movies not /media/movies.

Docker Compose Up

Once we got those changes added, we navigate to that Plex folder and run our docker-compose

  • cd /media/plex
  • docker-compose up -d

Plex should be now up and running!  Open a browser and visit the Plex web UI.  http://localhost:32400 This should bring you straight through the Plex setup.  

During the add media setup, remember to add the right folder: /movies for movies and /tv for TV shows.

That should be it!  On the next post we go over setting up Tautulli, Sonarr, Radarr, and SABNZBD.