Remote-access Guide

plex docker remote access

by Mr. Shane Schulist V Published 2 years ago Updated 1 year ago
image

How do I connect to Plex from a docker container?

I run my Plex instance in a Docker container, and there are two ways currently set up to access it: directly hitting the server with Docker Bridge networking on port 32400 going through Traefik using an internal host name and https on port 443

How can I run Docker on a remote server?

If your local system isn't powerful enough to run containers, or say you don't have enough storage, you can use a remote server for your docker host, and control it remotely via a TCP port or SSH. Expanding the previous point, servers on the cloud are nowadays very scalable.

How can I monitor Docker containers with Portainer?

Many monitoring tools, like Portainer, need access to the Docker API endpoint to monitor details like networks, running containers, etc. Normally to add a server to the endpoint list, you'd have to deploy a Portainer agent on the server first and bind some port from the container to the host.

How do I connect to traefik using Docker bridge?

directly hitting the server with Docker Bridge networking on port 32400 going through Traefik using an internal host name and https on port 443 Both of these are configured, in this order, with the “ADVERTISE_IP” environment variable set so these names are advertised.

image

The Problem

It appears that the majority of Plex clients on my network were considering the server to be a “remote” server, and so were setting bandwidth restrictions on playback.

Plex Server Setup

I run my Plex instance in a Docker container, and there are two ways currently set up to access it:

Why do clients think the server is Remote?

When I started writing this up, there was a much more hacky solution involving custom DNS entries for <my id>.plex.direct records which solved this part. However it appears the solution was much more simple.

Usage

Before you create your container, you must decide on the type of networking you wish to use. There are essentially three types of networking available:

Tags

In addition to the standard version and latest tags, two other tags exist: plexpass and public. These two images behave differently than your typical containers. These two images do not have any Plex Media Server binary installed.

Config Directory

Inside the docker container, the database is stored with a Library/Application Support/Plex Media Server in the config directory.

Fedora, CentOS, Red Hat

If you get the following output after you have started the container, then this is due to a patched version of Docker ( #158)

Running on a headless server with container using host networking

If the claim token is not added during initial configuration you will need to use ssh tunneling to gain access and setup the server for first run. During first run you setup the server to make it available and configurable.

Compose

The image I’ll be using is plexinc/pms-docker. Below is the compose file I’m using.

Plex Claim

You need to use the Plex Claim in order to add this server to your plex account. The procedure for getting the actual token you need is as follows

Creating Your Library

I also went ahead and created several folders under home/docker/plexms/media (“movies”, “music” and “tvshows”). These become the basis for my media libraries and I will need to populate these. I will probably add an external drive to Proxmox and use that as my file store, but that’s for another tutorial.

Further Reading

If any of you are using pfSense, then I have an article here which details how I managed to take care of some firewall issues I was having with Plex. You can read more about that here.

What port does plex use?

-p 32400:32400/tcp Forwards port 32 400 from the host to the container. This is the primary port that Plex uses for communication and is required for Plex Media Server to operate.

How does Docker work on Windows?

Docker on Windows works differently than it does on Linux; it uses a VM to run a stripped-down Linux and then runs docker within that. The volume mounts are exposed to the docker in this VM via SMB mounts. While this is fine for media, it is unacceptable for the /config directory because SMB does not support file locking. This will eventually corrupt your database which can lead to slow behavior and crashes. If you must run in docker on Windows, you should put the /config directory mount inside the VM and not on the Windows host. It's worth noting that this warning also extends to other containers which use SQLite databases.

Can you use Docker Compose on ARM?

Using docker-compose on ARM devices. The provided docker-compose templates use the plexinc/pms-docker image which is the amd64 build and won't work on ARM devices. To use docker-compose with ARM devices, you must first build one of the ARM images locally.

Can Plex Media Server run outside the container?

Permissions of mounted media outside the container do apply to the Plex Media Server running within the container. As stated above, the Plex Media Server runs as a specially created plex user within the container. This user may not exist outside the container and so the PLEX_UID and PLEX_GID parameters are used to set the user id and group id of this user within the container. If you wish for the Plex Media Server to run under the same permissions as your own user, execute the following to find out these ids:

What is Docker's main component?

Docker works in something called a client-server architecture. The main component that handles all your containers, volumes, networks, etc is the docker daemon that runs in the background. The docker command is nothing but the client application.

What do you need to tell your Docker engine and client about them?

Once the certificates and private keys are ready, you need to tell your docker engine and client about them, along with exposing the engine API to a public TCP port and letting the client use the docker engine that's not sitting at the local machine.

Can Portainer be remotely accessed?

All can be done remotely. Many monitoring tools, like Portainer, need access to the Docker API endpoint to monitor details like networks, running containers, etc. Normally to add a server to the endpoint list, you'd have to deploy a Portainer agent on the server first and bind some port from the container to the host.

image

Installing Docker

  • This command will fetch the docker installation script and execute it. curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh For security purposes, if you want to have a dedicated user for the Plex container, we can run some commands so the user can run docker without sudo privileges. sudo groupadd dockersudo gpasswd -a $USER docker To verify that the installation …
See more on github.com

Creating The macvlan Network

  • Simply put, a container connected to a Macvlan Network has its own MAC address, making it appear like it is a physical device directly connected to the network. It is like an equivalent of the bridge-networking in virtual machine applications. docker network create -d macvlan --subnet=192.168.0.0/24 --gateway=192.168.0.1 --ip-range 192.168.0.240/28 -o parent=eth0 pub_…
See more on github.com

Creating The Plex Container

  • Before we create the container, we have to create the folders that are required for plex: *config, media and transcode". (transcode is optional). We go to the user's home and run the following commands: cd ~ mkdir plex cd plex mkdir media Note that if you are hosting your media like me on a removable drive, you can skip the above command Next, we create and run the plex contain…
See more on github.com

Next Steps

  • After the initial configuration, you have to enable port forwarding in your router to map the local port to the public port. For simplicity purposes we can set it to 32400:32400. Next, we go the Plex web interface/app -> Settings -> Remote Access (Left-hand side) -> Input the ports. I recommend manually opening the ports vs. UPNP for better securit...
See more on github.com

Usage

Parameters

Users/Groups

Tags

Config Directory

Useful Information

  1. Start the container: docker start plex
  2. Stop the conrainer: docker stop plex
  3. Shell access to the container while it is running: docker exec -it plex /bin/bash
  4. See the logs given by the startup script in real time: docker logs -f plex
See more on hub.docker.com

Fedora, CentOS, Red Hat

Running on A Headless Server with Container Using Host Networking

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9