Plex in Docker
Skip the setup and get Plex "ElfHosted"!
Want to skip the self-assembly, and have Plex INSTANTLY "Just Workβ’"?
ElfHosted is an open-source app hosting platform (geek-cookbook-as-a-service), crafted with love by @funkypenguin - get your ElfHosted instance of Plex now!
Plex is a client-server media player system and software suite comprising two main components (a media server and client applications)
Plex Requirements
Ingredients
Already deployed:
- Docker swarm cluster with persistent shared storage
- Traefik configured per design
- DNS entry for the hostname you intend to use (or a wildcard), pointed to your keepalived IP
Related:
- Traefik Forward Auth or Authelia to secure your Traefik-exposed services with an additional layer of authentication
Preparation
Setup data locations
We'll need a directories to bind-mount into our container for Plex to store its library, so create /var/data/plex:
mkdir /var/data/plex
Prepare Plex environment
Create plex.env, and populate with the following variables. Set PUID and GUID to the UID and GID of the user who owns your media files, on the local filesystem
EDGE=1
VERSION=latest
PUID=42
PGID=42
Plex Docker Swarm config
Create a docker swarm config file in docker-compose syntax (v3), something like the example below:
Fast-track with premix! π
"Premix" is a git repository which includes necessary docker-compose and env files for all published recipes. This means that you can launch any recipe with just a git pull
and a docker stack deploy
π.
π Update: Premix now includes an ansible playbook, enabling you to deploy an entire stack + recipes, with a single ansible command! (more here)
version: "3.0"
services:
plex:
image: lscr.io/linuxserver/plex
env_file: plex.env
volumes:
- /var/data/config/plex:/config
- /var/data/media:/media
deploy:
labels:
# traefik common
- traefik.enable=true
- traefik.docker.network=traefik_public
# traefikv1
- traefik.frontend.rule=Host:plex.example.com
- traefik.port=32400
# traefikv2
- "traefik.http.routers.plex.rule=Host(`plex.example.com`)"
- "traefik.http.services.plex.loadbalancer.server.port=32400"
- "traefik.enable=true"
networks:
- traefik_public
- internal
ports:
- 32469:32469
- 32400:32400
- 32401:32401
- 3005:3005
- 8324:8324
- 1900:1900/udp
- 32410:32410/udp
- 32412:32412/udp
- 32413:32413/udp
- 32414:32414/udp
networks:
traefik_public:
external: true
internal:
driver: overlay
ipam:
config:
- subnet: 172.16.16.0/24
Note
Setup unique static subnets for every stack you deploy. This avoids IP/gateway conflicts which can otherwise occur when you're creating/removing stacks a lot. See my list here.
Serving
Launch Plex stack
Launch the Plex stack by running docker stack deploy plex -c <path -to-docker-compose.yml>
Log into your new instance at https://YOUR-FQDN (You'll need to setup a plex.tv login for remote access / discovery to work from certain clients)
Chef's notes π
-
Plex uses port 32400 for remote access, using your plex.tv user/password to authenticate you. The inclusion of the traefik proxy in this recipe is simply to allow you to use the web client (as opposed to a client app) by connecting directly to your instance, as opposed to browsing your media via https://plex.tv/webΒ β©
-
Got an NVIDIA GPU? See this blog post re how to use your GPU to transcode your media!Β β©
Tip your waiter (sponsor) π
Did you receive excellent service? Want to compliment the chef? (..and support development of current and future recipes!) Sponsor me on Github / Ko-Fi / Patreon, or see the contribute page for more (free or paid) ways to say thank you! π
Employ your chef (engage) π€
Is this too much of a geeky PITA? Do you just want results, stat? I do this for a living - I'm a full-time Kubernetes contractor, providing consulting and engineering expertise to businesses needing short-term, short-notice support in the cloud-native space, including AWS/Azure/GKE, Kubernetes, CI/CD and automation.
Learn more about working with me here.
Flirt with waiter (subscribe) π
Want to know now when this recipe gets updated, or when future recipes are added? Subscribe to the RSS feed, or leave your email address below, and we'll keep you updated.