Back

How to Install Plex on a Synology Using Docker

In this post I’m going to show you how you can run the media server Plex in a Docker container on your Synology NAS.

In case you don’t yet know what Docker is, I’ve written an article about Docker.

Why Would You Want to Use Docker?

The Plex package that Synology offers is always a few version numbers behind the package you can get directly from Plex. Now, the problem with that package directly from Plex is that you can’t have it update automatically, and the manual update process is cumbersome. Docker makes it easier to always have the latest version of Plex.

Another reason is that Docker allows applications to be bundled together with their dependencies into an isolated container. In the past, some DSM updates (e.g., the DSM 6 betas) broke the Plex installation because they removed or altered Plex’s dependencies. This could happen again with any DSM update in the future. The risk is always there. But not so with Docker containers. Since Docker bundles the application with its dependencies, it separates application dependencies from infrastructure. Docker basically adds a layer of abstraction that prevents things from going wrong.

Requirements

First, be sure that your Synology supports Docker. You need a Synology that has a CPU with the x86 architecture. Most cheaper models have a CPU with the ARM architecture which will not work. You can check out here which CPU architecture your Synology has.

There are a few guides out there how to get Docker running on unsupported models but make no mistake. Even if you could somehow get Docker running on an unsupported platform, those cheaper models with ARM CPUs are simply too weak to run Docker containers. The cheapest model with Docker support currently is the DS218+, but it has only 2 GB of RAM. 2 GB of RAM will allow the Synology to run a few (maybe five) containers at the same time but not more. You’ll want to use a more potent Synology with enough RAM if you want to run more Docker containers at the same time. I use a DS918+ which has 4 GB of RAM by default and a free slot for additional RAM. It runs Docker containers very well.

Docker and Hardware Transcoding

There’s one potential downside of running Plex in a Docker container. If you run Plex in a Docker container (rather than as a package), you won’t be able to make use of the hardware transcoding chip inside your Synology. This chip was specifically built and optimized for the purpose of (efficient) transcoding. In my eyes, this downside is not really a problem, i.e., it does not matter to me at all. To understand whether or not this is a problem to you, you need to understand the differences between Direct Play, Direct Stream, and Transcoding. Here’s my situation (and most likely yours as well): all my movies are MKV files, encoded with x264 into the H.264 format. And all modern devices, including smartphones and tablets, can play/decode such files. Therefore, there’s no need for transcoding in the first place, and thus it does not matter whether or not Plex can make use of the hardware transcoding chip. Similarly, you don’t need a Chinese translator if you only ever talk with English-speaking people. You wouldn’t mind whether you had the translator or not because you’d have no need for him anyway. Besides, you can only make use of hardware transcoding if you pay for the Plex Pass (and also run the package directly from Plex). Therefore, if you’re not paying for the Plex Pass, it doesn’t matter (in regard to hardware transcoding) whether you’re running Plex in a Docker container or as a package. You won’t be able to make use of hardware transcoding in either case.

One thing worth mentioning though: if the audio track of your movie is a DTS or AC3 track and you want to watch the movie on your iPhone/iPad or in the web browser, the audio track will have to be transcoded, since a web browser or iPhone/iPad can’t handle either of those. However, only the audio track has to be transcoded, not the video track. And transcoding audio tracks is by far not as demanding as transcoding video tracks. For transcoding audio, software transcoding is sufficient. To summarize: the CPU isn’t specifically built for transcoding, so it will do all the transcoding work much less efficiently in software. By brute force instead of clever tricks. While transcoding video in software would impose quite a burden on the CPU, transcoding audio in software is hardly an inconvenience for the CPU.

The only time when hardware transcoding would really make a difference is when you are away from home, e.g., in a hotel room and want to stream a movie from your NAS at home over the internet to your hotel room. Depending on how crappy their internet connection is (or how low your upload speed at home is), you could tell Plex to serve you a lower-bandwith version of your movie if the connection is not fast enough for the original high-definition resolution. In this case, Plex would have to transcode the video track. The real bottleneck here, however, is the upload speed of your internet connection at home. Since I never stream movies from outside of my home network, I really have no reason to care about hardware transcoding.

With all that said, let’s get Plex up and running in a Docker container!

Install the Docker Package

Go to Synology’s Package Manager, search for “Docker” and install it. It’s pretty straight-forward.

Additional Steps

Before we can start using Docker containers we have to make some preparations.

Connect to your Synology with SSH

We will use the command line interface, so make sure that SSH is enabled on your Synology. You can find that option under Control Panel > Terminal & SNMP > Terminal. You should also have assigned a static IP address to your DiskStation.

Now that SSH is enabled, you can log in to your DiskStation. If you’re on Windows, I guess you have to use PuTTY for that. I’m not a Windows guy though, so follow this tutorial to configure PuTTY. It’s easier if you’re using macOS or Linux. Simply open the terminal on your computer and issue the following command (use your own user name and replace the IP address with your Synology’s IP address beforehand):

ssh david@192.168.x.x

Now enter that account’s password or copy & paste it from your password manager. The account you use to authenticate yourself has to have administrator rights, otherwise it won’t work.

Download the Plex Image

Executing docker commands requires root privileges, i.e., you have to type sudo in front of every command. You can verify that by trying to download the Plex image without the sudo. It will not work.

docker pull linuxserver/plex

You probably received the error message docker: Got permission denied while trying to connect to the Docker daemon socket at …. Let’s fix that!

Since running docker commands in combination with sudo can be dangerous, we’d rather avoid it. Instead, we heed the advice of this site:

If you don’t want to use sudo when you use the docker command, create a Unix group called docker and add users to it.

Inconveniently, we can’t use the commands that site is proposing to create the docker group, since DSM is not a full Linux system and therefore lacks the mentioned tools such as usermod. That’s not a problem though. We just have to adapt the commands a little bit. Instead, we use the following Synology-specific command (replace david with your own username):

sudo synogroup --add docker david

This command created a user group called docker and added the user david to said group. That means that the stated user can now issue docker commands without having to put sudo in front of them, because:

When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.

Next, you need to re-evaluate your group membership. To do that, log out by typing

exit

into the terminal and then log back in using the same command as above.

For the effects to take place, we need to restart the docker daemon. To do so, you have several equivalent options. You could use either the GUI or this terminal command:

sudo synoservice --restart pkgctl-Docker

Alternatively, you could also use these commands:

sudo synoservicecfg --stop pkgctl-Docker
sudo synoservicecfg --start pkgctl-Docker

Now you should be able to run docker commands without sudo:

docker pull linuxserver/plex

This time, it should have worked. That last command downloaded the Docker image for Plex by Linuxserver. Linuxserver is a great resource for Docker images. Their Plex image is better than the official image from Plex. Their images have good documentation, are very well maintained and, most importantly, they can auto-update without you having to download the latest image manually.

Create the Mount Points

Next, we need to create the volumes we’re going to mount later on. Sounds complicated but is really simple. Go back to the terminal, log back in if necessary, and create two new folders:

mkdir -p "/volume1/docker/plex/config"
mkdir -p "/volume1/docker/plex/transcode"

You may have noticed that when you installed the Docker package, Docker created a new shared folder called docker. Inside that shared folder, we just created a new subfolder called plex and inside that plex folder, we created two more subfolders. You should create a folder inside docker for every application you want to run in a Docker container, not just for Plex. The reason is: we don’t want an application to store its configuration files inside its container but somewhere we can access them. The whole purpose of Docker, after all, is that containers are meant to be disposable. If something doesn’t work anymore, throw the container away and create a new one. If you store your configuration files inside the container, you’d throw them away together with the container and lose all your settings. We’d rather store the settings outside the Docker container so that we can delete and create containers at will without having to reconfigure Plex each and every time. Since Docker containers cannot see the file system of their host, we’ll have to define mount points that point to specific folders. And we just created these specific folders.

In case you already had the Plex package installed before you decided to run Plex in a container, you can migrate your existing Plex settings to Docker by following this article. Basically, you just move the Library folder out of the shared folder called Plex inside the newly created folder /volume1/docker/plex/config. It’s best to use the GUI in your web browser to move that folder. If you want to do it from the terminal, you’d have to log in as root user, since you cannot see shared folders when you’re logged in as admin account (admin accounts are just regular accounts in this scenario).

Create the Docker Container

Finally, we can create the Docker container. Depending on how you organize your media, you will have to adjust the following command to your own specific situation. I have a shared folder called Media in which I have different subfolders called TV Shows, Movies, and Music. If your folders are named differently, replace the path to the left of the colon accordingly but leave the right side as is. If you don’t want to add e.g., your music to Plex, omit the appropriate line. If you’d like to also add your photos folder, add an appropriate line.

Since I live in Germany, my time zone is Europe/Berlin. You have to replace that with your own time zone (which you can find here).

Leave everything else as is. Copy the entire code snippet and paste it into the terminal as one single big command (log back in via SSH if necessary).

docker run \
--name=plex \
--net=host \
--restart=always \
-e VERSION=latest \
-e PUID=$(id -u) -e PGID=$(id -g) \
-e TZ=Europe/Berlin \
-v "/volume1/docker/plex/config":/config \
-v "/volume1/docker/plex/transcode":/transcode \
-v "/volume1/Media/Movies":/data/movies \
-v "/volume1/Media/TV Shows":/data/tvshows \
-v "/volume1/Media/Music":/data/music \
linuxserver/plex

This command creates an actual container out of the image. Since we’re using --net=host, we don’t need to take care of any sort of port forwarding. There are applications and advanced use cases where you want to use bridge instead, but for our purpose of creating a simple Plex container host is sufficient and the preferred option.

A Word on Environment Variables

This section is solely for your information. It does not contain any commands you need to execute. If you’re not interested in the details, you may skip this section. I just want to inform you about one of the many reasons why I wasn’t quite content with the existing guides and wanted to write my own, more coherent guide.

In order for the Docker container to access your media, we first need to give it permission. Most other guides would make you find out your user ID (UID) manually (it should be a four-digit number around 1026). Then, these guides would make you write that number down somewhere and save it for later. Next, they would make you find out your group ID (GID)—manually again. Both of which would be achieved using the command id. Then, these guides would have you set PUID equal UID and PGID equal GID. All of this would be done manually. This is not very efficient. I spared you that. If you take a closer look at the command from above, you will notice the line -e PUID=$(id -u) -e PGID=$(id -g). This line does everything mentioned automatically for you. It also obviates the risk of setting the wrong group ID. The group ID 100 stands for the user group, the group ID 101 for the administrator group. Since you’re logged in as administrator, the id command would show that your account belongs to both 100 and 101. Many guides would make you set 101 as PGID. I don’t recommend that. Unless you really want to grant Plex administrator rights—which you shouldn’t do and certainly do not need to do—you should set PGID to be 100 (and thus give Plex only the access permissions of a regular user). 100 is also what id -g returns. I hope this made the command from above a little bit clearer.

Open Plex

The container should have started by now. If not, give it a few more second. Now, you can finally start using Plex. Replace the IP address in http://192.168.x.x:32400/web with your own Synology’s address, open that URL in your web browser and save it as a bookmark.

In Plex, you’ll probably have to adjust some settings, e.g., add the tvshows, movies, and music folders to your media library. Apart from this, that’s it! I hope you now have a working Plex setup.

Fix Transcoding Issues

I used to have a lot of problems with transcoding. Although my media was encoded into the correct format (H.264), i.e., qualified for Direct Play / Direct Stream, Plex was always transcoding it. The problem turned out to be the subtitles. With the wrong settings, Plex would “burn in” the subtitles, thus making it necessary to transcode the video stream. To fix this problem, first of all, be sure that all subtitles are, a) external files and, b) in the SRT format. Then, in the Plex settings, enable the advanced settings and go to Web > Player > Burn subtitles and change it from Automatic to Only image formats. This solved my transcoding problems.

Image of best subtitles setting
Image of best subtitles setting

Final Words

If you liked this article, share it with your friends and fellow Plex users. Feel free to post it in forums as well. As you can see by now, running Plex in a Docker container is not that hard once you’ve wrapped your head around it. I found the existing guides to be very confusing, however. It would be great if I could help some more people out. Cheers!

As an Amazon Associate I earn from qualifying purchases.
Built with Hugo
Theme Stack designed by Jimmy