Creating the ultimate media server with Docker, Portainer, Plex, and Ubuntu Server
I’ve been meaning to set up an Ubuntu server to run some docker containers as a personal project for some time. I stumbled onto some self hosting subreddits, watched a few videos about Portainer and had to try it out for myself. I had run a Plex server for my house in the past, but I was managing it manually. What a fool I was to be doing all that work! I could have been automating everything with Docker the whole time. The server we are going to make will automatically handle requests with Sonarr or Radarr, download them via usenet or torrent, then load them into Plex for viewing.
On of the things I love about this build is that we can run a VPN through the torrent container only. We maintain our anonymity when using public torrent trackers as well as maintain normal download and upload speeds outside of the container.
First, we need a fresh install of Ubuntu Server. I can’t recommend Ventoy enough.
The current stack:
Plex
Sonarr
Radarr
Jackett
Organizr
QBittorrentVPN
SABnzbd
Prometheus
Grafana
We need our Ubuntu Server install. The only additional selection needed is to install SSH.
Things I always do on a fresh install
$ sudo apt update && sudo apt upgrade -y
Install vim:
$ sudo apt install vim -y$ ifconfig
Take note of the name of your Ethernet interface. We need to set a static IP for the server on the network.
Edit our netplan config to do so.
$ sudo vim /etc/netplan/00-installer-config.yml
Make the following changes (change to the name of your interface and what ip address you want):
network:
ethernets:
ethernetname:
dhcp4: false
addresses: [192.168.1.xxx/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8,8.8.4.4,192.168.1.1]
version: 2
And then lastly follow up with a $ sudo netplan apply
Most importantly we need to set up our firewall. Be sure to add rules for ports and services we need as we go along adding containers and such.
$ sudo ufw default deny incoming
$ sudo ufw default allow outgoing
$ sudo ufw allow ssh
$ sudo ufw enable
Swappiness is 60 by default which is fine in most cases. But if you decrease this number, your system will use RAM more and start writing to Swap much later. Swap is an actual disk space and it is much slower than RAM. If you have 8G or more of RAM, you can force your system to use it at maximum.
First, check your swappiness value:
cat /proc/sys/vm/swappiness
Open the /etc/sysctl.conf
file with Vim:
sudo vim /etc/sysctl.conf
And add vm.swappiness = 10
at the very end.
Now I’m going to set a couple external drives to automount. These drives will serve all of our files and host our config files and such. I have them both formatted to ext4.
First we need to get the UUIDs we need to mount.
$ sudo blkid
Create directories where we ant to mount our drives.
Before we add the entry to fstab, we must first create a mount point for the drive. The mount point is the directory where users will access the data on the drive.
So let’s create a directory with the command:
$ sudo mkdir
You’ll want to also change the group ownership of that directory, so that users can access it. For this, you might create a group called data and then add users to the new group. This could be done with the commands:
$ sudo groupadd GROUPNAME
$ sudo usermod -aG g USERNAME
After you’ve done that, you could then change the ownership of the mountpoint with the command:
$ sudo chown -R :GROUPNAME /media/NAME
Then we edit our fstab file to set our mount point
$ sudo vim /etc/fstab
Add the entries with the UUIDs we copied a moment ago.
We need to append one line of code at the end of the file. The format of this line of code is as follows:
UUID=<uuid-of-your-drive> <mount-point> <file-system-type> <mount-option> <dump> <pass>
Note that you need to separate these items with Tab key. For example, I added the following line to the end of /etc/fstab
. my mount point is /media/mypassport
UUID=fd276feb-dd7e-4176-bc77-fc9e6ca43ecb /media/mypassport ext4 defaults 0 2
Now we will install docker as well as follow the additional Post-installation steps for Linux which will allow us to manage docker as a non-root user. Also install Docker Compose.
With two more commands, we install Portainer. It gives us a nice web UI to manage our Docker containers. Log into the Web UI using the host or ip of our new server.
You’re greeted with a login and password reset screen.
Then go to, environments and then click on “local”. Under Public IP Add the Static IP we assigned earlier.
Now let’s add and deploy our stack. Be sure to edit the volume locations to match the drives we mounted earlier. Also, enter VPN credentials for QBittorrent. If you have problems connecting to any of the web UIs, make sure you have a rule in your firewall for the needed ports. Also, you can swap Plex out of the Docker compose file with something like Emby or Jellyfin if you choose.
Your VPN provider should most likely support OpenVPN. You need to find where these files are offered by your VPN provider and add them to /Configs/QBittorrent/openvpn/
go to Stacks > Add Stack
Name the stack and paste your docker compose file in the Web Editor.
We need to make sure Prometheus has the config file it needs. go to /Configs/Prometheus
$ sudo vim prometheus.yml
Add the following, make sure to edit and include your servers
Once you’re comfortable with your docker-compose file, click the button below to deploy the stack.
Once finished, you can see everything running correctly. Click the ports under Published Ports to load up each containers Web UI and start configuring them.
If you want to download via usenet, start by adding an nzb indexer in Sonarr and Radarr. If you are wanting to use torrents, add your indexers in Jackett, then load them into Sonarr and Radarr.
Configure your download clients and Remote Path Mappings. Pointing it to your Downloads folder.
Under Media Management, set permissions to 775 and set the root folder your media folder. In this case it’s Sonarr so it’s pointed towards my TV folder.
Going to Library Import on the left will let you import anything you may already have in your root folder. Head over to the internet archive and grab some free to use video (It’s great for finding VHS rips) or rip a Bluray or DVD you own and see if it’s picked up when you do an import. Then you will know you have your paths mapped correctly. I’ve ripped my entire DVD and Bluray collection and it was nice to have everything import and ready to watch within a few minutes.
Now that Sonarr, Radarr, and our downloaders are working, let’s set up Plex.
To access Plex:
https://localhost:32400/web/index.html
Go through the initial set up and add your libraries.
Moving on, next is Grafana.
Login with username and pasword admin/admin and it will prompt you to change it on first login.
Add a new data source. Choose Prometheus.
Enter in the URL with your servers IP and port for Prometheus. verify what ports you need by looking at Portainer.
Save and Test.
Then, on the left side go to create (+) and then import. Enter in 11074.
Then on the next screen choose Prometheus in the drop down and import.
Then you’ll see your shiny new dashboard which will then begin collecting data, you may need to give it a moment.
With Prometheus and Grafana playing nicely. We can now configure organizr.
Choose personal as your install type. enter your password and email.
Type in anything for a Hash Key to move forward. Then enter password. Create and name your database.
Before we can move on with Organizr, open Qbittorrent’s Web UI.
Then go to Options>Web UI>Security and uncheck Enable Clickjacking protection and Host header validation. Save.
Back in Organizr, add a new tab. Name it QBittorrent and enter in your host URL and port number. Select the QBittorrent image. Test and add.
Go to tab editor and you will now see QBittorrent. Click the house icon to edit.
Enable and set Minimum Authentication.
Under connection add your server, port, API V2, and username and password for QBittorrent. Save and test.
Enable Homepage and QBittorrent in tab editor.
Refresh and we now have it on the homepage! You can do the same for your other applications to have all of your server Web UIs in one place.
You will need to go into QBittorrent and confirm your download folders. With Sonarr and Radarr your search results will only be as good as the indexers you choose. I would definitely recommend doing some research on what indexers may work best for your needs. Thank you for reading.
I do not condone piracy or profiting from the stolen intellectual property of others. This is a server project for personal use.