pms-docker

repository·master·Indexed 26 days ago

https://github.com/plexinc/pms-docker

Official Docker container for Plex Media Server. Supports various networking modes including Bridge, Host, and Macvlan. Includes a plex-media-server Helm chart for Kubernetes deployments with support for rclone remote storage mounting, NVIDIA GPU configuration, and custom init container scripts for migrating existing PMS databases.

Tokens
5.6K
Snippets
9
Records
20
Agent score
88%

What's inside pms-docker

  1. Migrate Ingress TLS configuration from v0.9.x to v1.x

    master

    When upgrading from version v0.9.x to v1.x, the method for defining TLS configuration in the Ingress resource has changed. You must replace the certificateSecret field with a tls block. This allows for more flexible host-to-secret mapping.

    # Old configuration (v0.9.x)
    certificateSecret: plex.example.com
    
    # New configuration (v1.x)
    tls:
    - hosts:
      - plex.example.com
      secretName: cert-example-com
  2. Enable Intel Quick Sync Hardware Transcoding

    master

    If you have a Plex Pass subscription and a supported Intel CPU, you can enable hardware transcoding by passing the kernel device to the container.

    1. Verify Host Support

    Run the following command on your host to ensure the i915 driver is in use: lspci -v -s $(lspci | grep VGA | cut -d" " -f 1)

    2. Run Container with Device Mapping

    Add the --device=/dev/dri:/dev/dri flag to your docker run command:

    docker run \
    -d \
    --name plex \
    --network=host \
    -e TZ="<timezone>" \
    -e PLEX_CLAIM="<claimToken>" \
    -v <path/to/plex/database>:/config \
    -v <path/to/transcode/temp>:/transcode \
    -v <path/to/media>:/data \
    --device=/dev/dri:/dev/dri \
    plexinc/pms-docker

    3. Enable in Plex Web App

    1. Open the Plex Web app.
    2. Navigate to Settings > Server > Transcoder.
    3. Click Show Advanced in the upper-right corner.
    4. Turn on Use hardware acceleration when available.
    5. Click Save Changes.
  3. Access headless Plex server via SSH tunnel

    master

    If you are setting up Plex on a headless server and did not provide a PLEX_CLAIM token, the initial setup wizard only triggers if you access the server via http://localhost:32400/web. To achieve this from your local machine, create an SSH tunnel:

    ssh username@ip_of_server -L 32400:ip_of_server:32400 -N

    After running this, you can access the setup wizard by navigating to http://localhost:32400/web on your local computer.

  4. Migrate an existing Plex configuration directory

    master

    To move an existing Plex installation to the Docker /config directory:

    1. Identify your current config directory. If it is /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/, your new Docker config root will be /var/lib/plexmediaserver.
    2. If your current directory does not follow the Library/Application Support/Plex Media Server/ structure, create a new directory for Docker and manually create the subfolders:
      • [new_config_dir]/Library/Application Support/Plex Media Server/
    3. Copy your existing Plex Media Server folder into that new path.
    4. Ensure the container has permissions (or use CHANGE_CONFIG_DIR_OWNERSHIP=true).
  5. Set User Permissions (UID/GID)

    master
    Plex runs as a plex user inside the container. To ensure the container has the same permissions as your host user, find your current UID and GID using the id command, then pass them via PLEX_UID and PLEX_GID.
  6. Deploy Plex Media Server using Bridge Networking

    master

    Bridge networking (the default) creates a new network within the host. This is the most complex setup because the server is essentially behind two routers.

    Important Considerations:

    • Remote Access: You must manually configure port forwarding on your router to the ADVERTISE_IP specified. By default, forward port 32400.
    • LAN Access: (Plex Pass only) After setup, configure the LAN Networks preference in Plex to include your LAN subnet (e.g., 192.168.1.0/24) to ensure proper bandwidth control.
    docker run \
    -d \
    --name plex \
    -p 32400:32400/tcp \
    -p 8324:8324/tcp \
    -p 32469:32469/tcp \
    -p 1900:1900/udp \
    -p 32410:32410/udp \
    -p 32412:32412/udp \
    -p 32413:32413/udp \
    -p 32414:32414/udp \
    -e TZ="<timezone>" \
    -e PLEX_CLAIM="<claimToken>" \
    -e ADVERTISE_IP="http://<hostIPAddress>:32400/" \
    -h <HOSTNAME> \
    -v <path/to/plex/database>:/config \
    -v <path/to/transcode/temp>:/transcode \
    -v <path/to/media>:/data \
    plexinc/pms-docker
  7. Deploy Plex Media Server using Macvlan Networking

    master

    Macvlan networking creates a new virtual computer on the network for the container. This setup is similar to Host networking but requires specifying a network and an IP address.

    Requirements:

    • You must have a macvlan network already configured on your Docker host (e.g., named physical).
    • You must specify a unique IP address for the container.
    docker run \
    -d \
    --name plex \
    --network=physical \
    --ip=<IPAddress> \
    -e TZ="<timezone>" \
    -e PLEX_CLAIM="<claimToken>" \
    -h <HOSTNAME> \
    -v <path/to/plex/database>:/config \
    -v <path/to/transcode/temp>:/transcode \
    -v <path/to/media>:/data \
    plexinc/pms-docker
  8. Migrate existing PMS database using an init container script

    master

    If you are migrating an existing PMS server to Kubernetes, you can use a custom initContainer.script to import your existing Library directory.

    Important: The script must include a check to exit early if the database already exists to prevent overwriting data on pod restarts.

    Example: Fetching database from a web server

    This script uses curl to download a compressed archive from a URL and extract it to /config.

    #!/bin/sh
    echo "fetching pre-existing pms database to import..."
    
    if [ -d "/config/Library" ]; then
      echo "PMS library already exists, exiting."
      exit 0
    fi
    
    apk --no-cache add curl
    curl http://example.com/pms.tgz -o pms.tgz
    tar -xvzf pms.tgz -C /config
    rm pms.tgz
    
    echo "Done."
    #!/bin/sh
    echo "fetching pre-existing pms database to import..."
    
    if [ -d "/config/Library" ]; then
      echo "PMS library already exists, exiting."
      exit 0
    fi
    
    apk --no-cache add curl
    curl http://example.com/pms.tgz -o pms.tgz
    tar -xvzf pms.tgz -C /config
    rm pms.tgz
    
    echo "Done."
  9. Migrate existing PMS database via manual file upload

    master

    If you cannot host your PMS database on a web server, you can manually upload the archive to the init container pod and have the script process it.

    Step 1: Use this init script

    This script waits for a file named /pms.tgz to appear before unpacking it.

    #!/bin/sh
    echo "waiting for pre-existing pms database to uploaded..."
    
    if [ -d "/config/Library" ]; then
      echo "PMS library already exists, exiting."
      exit 0
    fi
    
    # wait for the database archive to be manually copied to the server
    while [ ! -f /pms.tgz ]; do sleep 2; done;
    
    tar -xvzf /pms.tgz -C /config
    rm pms.tgz
    
    echo "Done."

    Step 2: Manual Upload Commands

    1. Copy the file to the pod using a temporary name to prevent the script from starting prematurely: kubectl cp pms.tgz <namespace>/<podname>:/pms.tgz.up -c <release name>-pms-chart-pms-init

    2. Rename the file on the pod to trigger the script: kubectl exec -n <namespace> --stdin --tty <pod> -c <release name>-pms-chart-pms-init -- mv /pms.tgz.up /pms.tgz

    #!/bin/sh
    echo "waiting for pre-existing pms database to uploaded..."
    
    if [ -d "/config/Library" ]; then
      echo "PMS library already exists, exiting."
      exit 0
    fi
    
    # wait for the database archive to be manually copied to the server
    while [ ! -f /pms.tgz ]; do sleep 2; done;
    
    tar -xvzf /pms.tgz -C /config
    rm pms.tgz
    
    echo "Done."
  10. Deploy Plex Media Server using Host Networking

    master

    Host networking uses the IP address of the host running Docker, making the container's networking appear as the host itself. This is one of the easiest setups with the fewest workarounds.

    Note: If your /etc/hosts file is missing an entry for localhost, add one before using this mode.

    docker run \
    -d \
    --name plex \
    --network=host \
    -e TZ="<timezone>" \
    -e PLEX_CLAIM="<claimToken>" \
    -v <path/to/plex/database>:/config \
    -v <path/to/transcode/temp>:/transcode \
    -v <path/to/media>:/data \
    plexinc/pms-docker
  11. Manage the Plex Docker container

    master

    Use the following standard Docker commands to manage your running Plex container (assuming the container is named plex):

    • Start: docker start plex
    • Stop: docker stop plex
    • Restart/Upgrade: docker restart plex (restarts the application and pulls the latest version if configured)
    • Shell Access: docker exec -it plex /bin/bash (access the container's bash shell)
    • View Logs: docker logs -f plex (view startup script logs in real time)
  12. Configure rclone for remote storage mounting

    master

    The rclone object in the Helm chart allows you to mount remote drives into the PMS container.

    • rclone.enabled: Set to true to create the rclone sidecar.
    • rclone.configSecret: The name of the secret containing the rclone configuration file. The key in the secret must be rclone.conf. All keys in the secret will be available in /etc/rclone/.
    • rclone.remotes: A list of remotes to mount. Format: name:[/optional/path]. These will be mounted at /data/name inside the PMS container.
    • rclone.readOnly: If true, remote volumes are mounted as read-only (default is true).
    • rclone.additionalArgs: Additional arguments passed to the rclone command.