Plex Docker Compose: KICKASS Media Server with HW Transcoding

Plex is the best Media Server right now. In this Plex Docker Compose guide you will learn how to install Plex easily, with hardware transcoding.

We have previously compared Plex vs Jellyfin vs Emby in detail. While some of the Plex alternatives, especially the free and awesome Jellyfin, have been giving Plex the run for the money.

But with plenty of free content, Plex is still the king of media servers. For this reason, it is in our list of best Docker containers for home servers.

Combined with a capable Plex Client device, you can build your own Netflix-type media server.

In this tutorial, I will present my working Plex Docker Compose example that will help you setup Plex using Docker in just a few minutes.

Plex Docker Compose Setup

Most Docker tutorials out there give you the Docker run command and ask you to copy-paste it into Portainer. [Read: Portainer Docker Compose: FREE & MUST-HAVE Container Manager]

Having used Docker for over 5 years (and being a person of non-IT background), I strongly suggest you take the time to learn Docker compose and build your stack using it.

Docker Compose gives you portability between systems. I can use the docker-compose files from my GitHub repo in my Ubuntu Server on Proxmox, my Ubuntu Server VPS on Digital Ocean, or even my Synology NAS and they will work the same.

If you use or picked Plex over Jellyfin/Emby as your media server, why did you do so?

View Results

Loading ... Loading ...

1. Preparing to Setup Plex Using Docker

If you already have docker and docker-compose installed, and have setup your .env file then skip to Docker Compose for Plex Media Server section below.

Requirements

First, let us start with some requirements. I won't go into a lot of details as these have been covered in detail in my Docker Media Server guide. Here is a summary of the requirements before Proceeding.

Setting Up The Docker Environment

This is also explained in detail in my Docker Guide. We are going to customize a few things with Docker before building the Plex Docker Compose file.

First, is the folder structure. I like to house all of the docker-related files and folders in one location. I call it the Docker Root Folder. Our docker-compose.yml, .env files, etc. will be located in this folder, as shown below.

Docker Media Server Folder Structure
Docker Media Server Folder Structure

In addition, all of Plex's data will go into the appdata/plex folder. For this guide, you do not need to worry about the remaining folders in the above screenshot.

Create the .env file

First, the dot in front of env is not a typo.

It is a hidden file that will store some of the key information we may use (environmental variables) repeatedly. In the docker root folder (explained above), create the .env file and add the following contents to it.

PUID=1000
PGID=1000
TZ="Europe/Zurich"
DOCKERDIR="/home/anand/docker"
DATADIR="/media/storage
SERVER_IP=192.168.1.111
LOCAL_NETWORK=192.168.0.0/16

Customizing the above variables is explained in detail in my Docker guide, along with the right permissions to set (very important!).

Explanation of Plex Environmental Variables
  • PUID and PGID are the user's user id and group id, obtained using the id command.
  • TZ is the timezone.
  • DOCKERDIR is the docker root folder mentioned above.
  • DATADIR is the location of files, which could be media files.
  • SERVER_IP is the IP of the docker host.
  • LOCAL_NETWORK is your local network subnet (for bandwidth regulation). Mine is 192.168.0.0/16, covering all IPs between 192.168.0.0 – 192.168.255.255, which also includes my ZeroTier-One network. Yours could be different.

In addition, replace 1000 and anand with your details.

2. Create the Base Plex Docker Compose File

Before we go ahead and add the Docker Compose for Plex, we will have to add a few basic elements to the compose file. Once again, this is all explained in detail in my Docker tutorial. But here is a summary of it.

Note that spacing and indentation are crucial in YAML files. Therefore, pay attention to the formatting when you copy-paste and customize the Plex Docker Compose snippet.

In your Docker Compose file, if you do not already have it, add the following:

version: "3.9"

########################### NETWORKS
networks:
  default:
    driver: bridge

########################### SERVICES
services:

We are specifying the version of Docker Compose reference to use and the default Docker bridge network. If you do not know what these are, do not worry.

We are going to make Plex accessible using the Docker Host machine's IP, using Plex's default port (e.g. http://192.68.1.111:32400). For this purpose, the above network block is sufficient.

Using Docker macvlan (OPTIONAL)

If for some reason, you would like Plex to have its own IP address in your network (e.g. port conflict with Docker Host), then you will have to use Docker's macvlan. Containers on macvlan will behave as if they are on a separate machine in your home network.

Plex requires many different ports to function properly, some of which may conflict with other services on your server.

Add the code block below right at the end of the above network block.

  dockervlan:
    name: dockervlan
    driver: macvlan
    driver_opts:
      parent: eth1 # using ifconfig
    ipam:
      config:
        - subnet: "192.168.1.0/24"
          ip_range: "192.168.1.250/32"
          gateway: "192.168.1.1"

Since my home network is in the subnet 192.168.1.X, I wanted Plex to have an IP in this range. A few things to customize. First, eth1 is the name of the network interface to use. You can find this using the ifconfig or ip address command.

Next, customize the subnet and IP. I am assigning 192.168.1.250 to Plex. The /32 at the end means only one IP. If you plan to put multiple containers on the same macvlan, you can use other numbers per your requirement (e.g. 29 for 5 machines, 30 for 2, etc.)

3. Docker Compose for Plex Media Server

Here is the Docker-Compose for Plex I recommend in my Docker media server guide. Add it right under services (pay attention to indentation):

  # Plex - Media Server
  plex:
    image: plexinc/pms-docker:public
    container_name: plex
    restart: unless-stopped
    networks:
      - default
    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"
      # - "33400:33400" # If you use Plex Web Tools
    # devices:
    #   - /dev/dri:/dev/dri # for hardware transcoding
    volumes:
      - $DOCKERDIR/appdata/plex:/config
      - $DATADIR/media:/media
      - /dev/shm:/transcode
    environment:
      TZ: $TZ
      HOSTNAME: "dockerPlex"
      PLEX_CLAIM: $PLEX_CLAIM
      PLEX_UID: $PUID
      PLEX_GID: $PGID
      ADVERTISE_IP: http://$SERVER_IP:32400/
      ALLOWED_NETWORKS: $LOCAL_NETWORK
You may find that the Docker Compose examples in my GitHub repo differ from the above. What is shown above is an example that is good for beginners to get started with. What is in my GitHub repo is my current setup with many features and security enhancements.

Customizing Plex Media Server Docker Setup

Here are some notes to understand and customize the above Plex docker-compose example:

  • We are using the plexinc/pms-docker:public Plex docker image. You could also use plexpass image, which offers some benefits, instead of public. With support for Plex on Raspberry Pi Docker servers (ARM), Linuxserver.io's Plex image is also a good one.
  • Plex will belong to the "default" bridge network. This is fine for most users. For advanced configurations, keep reading.
  • We are also mapping several of the Plex container ports (right side of the colon) to the Docker host (to the left of the colon). Plex will be available on the Docker host IP at Plex Docker port 32400. For example, my Docker host has an IP of 192.168.1.111. So Plex will be available at http://192.168.1.111:32400.
  • /dev/dri is usually the graphics card. You can pass your docker host's graphics card to the Plex docker container for hardware transcoding. Uncomment these lines (remove the # in front) to enable graphics cards. You will have to enable hardware transcoding in Plex settings. This is especially useful for NASes that support Plex (e.g. Synology).
  • Under volumes, we are mapping a persistent volume for Plex configuration, another volume that has our media. You could make it read-only by adding :ro at the end. Finally, we are passing RAM for faster transcoding (ensure that /transcode is set as the transcoding folder in Plex media server settings).
  • With $PUID and $PGID, we are specifying that Plex runs as the user id and user group, which we defined previously in .env file.
  • PLEX_CLAIM is your Plex claim token.
  • ADVERTISE_IP sets up the Custom server access URLs under Plex server Network settings. It specifies other IP addresses over which, the same Plex server may be reached.
  • ALLOWED_NETWORKS: This is purely for bandwidth regulation. The IPs specified here are considered local (LAN) networks.
Note: The first time you try to access a new Plex server you will either have to be on the local Plex server machine and use http://localhost:32400/web or use the IP address of the Plex server (e.g. http://192.168.1.111:32400/web).

Customizing Network

In the above Plex Docker Compose file, we set the network as default. This is fine. But if you wanted a macvlan for Plex that was described above, then replace the networks block with the following one.

    networks:
      dockervlan:
        ipv4_address: 192.168.1.250 # IP address inside the defined range

Note that the IP address specified is the same as what we configured previously in this guide. Plex should be available at http://192.168.1.250:32400.

Alternatively, you can specify the Plex server Docker container to use the host network. In this case, Plex functions as if it were running natively on your host system. This requires all necessary ports to be free (e.g. 32400, 1900, etc.). To enable host networking, use the following block instead of networks:

    network_mode: 'host'

In addition, you will also need to remove the ports section. Plex should be available at http://192.168.1.111:32400, which is the same URL as the default Plex docker compose setup shown previously.

Start Plex

After customizing the Plex Docker Compose file, you can start Plex using the following command:

sudo docker compose -f ~/docker/docker-compose.yml up -d

Be sure to refer to my Docker guide to understand how you can follow the logs to check the start-up of the Plex docker container. You may use Dozzle logs viewer for real-time logs viewing.

If all goes well, in a few minutes you should be to access Plex using one of the URLs listed previously.

Plex Login Screen
Plex Login Screen

4. Accessing Plex Over the Internet

Accessing Plex from within your home network should work fine (described above). But what if you want access to Plex on the go from outside your home network?

Well, there are many ways to do this.

The easiest and slightly insecure way to do this is to forward port 32400 on your router/gateway to point to your Plex servers IP address (same as ADVERTISE_IP defined above).

Authentication goes through Plex servers. Therefore, forwarding port 32400 on your router to your Plex server is not as big of a security risk as with some other self-hosted apps.

Accessing Plex with VPN

A secure way to access Plex is to connect to your home network using a VPN service. Home routers and network-attached storage devices sometimes come with a built-in VPN server. Once connected, you can use the same home network IP address of your Plex Docker server.

You may also use a third-party VPN mesh network such as Tailscale or Zerotier-One. I use ZeroTier to tie all my key machines together in a virtual network. My Docker host is part of this network. Therefore, while on the go, I can use my Docker host's ZeroTier network IP address with Plex's port number.

Another alternative is to set up your own Wireguard network. But this is a more advanced topic.

Other Posts in the Wireguard Series:

Exposing Plex with Reverse Proxy

Another secure way to access Plex is to put it behind a reverse proxy. But this requires a domain name or a DDNS.

Nginx Proxy Manager is very simple to setup but not very flexible.

I use and recommend Traefik. You can read all about setting it up in my Docker Traefik guide or refer to my GitHub repo.

With a reverse proxy, you can access Plex using a nicer URL (e.g. https://plex.example.com).

Note that using Cloudflare Proxy for media servers such as Plex and Jellyfin is against their terms. Your account will be suspended. Therefore, be sure to setup Cloudflare rules to bypass the cache as shown below (replace "jellyfin" with the subdomain for your Plex).
Bypass Cloudflare Cache For Plex
Bypass Cloudflare Cache For Media Servers (Jellyfin Example Shown)

Plex Docker Hardware Transcoding

As explained above, passing /dev/dri from the Docker host to the container makes the GPU available for the Plex media server docker container to use. In addition, hardware transcoding must be enabled in Plex transcoder settings as shown below.

Plex Hardware Transcoding On Docker
Plex Hardware Transcoding On Docker

Unfortunately, unlike Jellyfin, Plex does not make it easy to explicitly specify the GPU. Intel and Nvidia hardware work great. AMD devices, however, are out of luck as there is a lack of transparency.

In my case, with AMD Ryzen 7 4800u, it was a breeze to get hardware transcoding work on Jellyfin. On Plex, I had no luck even after following this lengthy thread.

This problem exists irrespective of whether you install Plex natively or use Docker.

Conclusions: Super Charging Plex on Docker

Plex is a powerful media center. In recent years, Plex has been adding many new features to enhance Plex pass experience, such as Plexamp, free movies/TV, integration with streaming services, and more. No other media server even comes close in this area. It's how Plex differentiates itself from the free Jellyfin.

Installing Plex natively on operating systems is not difficult.

But Docker makes it much easier to install Plex, and Docker Compose simplifies it even more. With the included Plex Docker Compose example and easy steps to install Plex, you should be up and running in just about 5 minutes.

Be sure to check out our Plex client devices and best NAS for Plex lists.

Be the 1 in 200,000. Help us sustain what we do.
46 / 150 by Dec 31, 2024
Join Us (starting from just $1.67/month)

Anand

Anand is a self-learned computer enthusiast, hopeless tinkerer (if it ain't broke, fix it), a part-time blogger, and a Scientist during the day. He has been blogging since 2010 on Linux, Ubuntu, Home/Media/File Servers, Smart Home Automation, and related HOW-TOs.