Installing Plex using Docker

In this post, we’ll explore how to install Plex media server using Docker. Docker provides a lightweight and portable way to run applications, making it an excellent choice for running Plex.

Prerequisites

  • You need to have Docker and Docker Compose installed on your system. You can download the installer from the official Docker website.
  • You should also have a valid Plex account and know your login credentials.
  • Tip: you can create your Plex account by visiting https://plex.tv
  • Create a Plex folder inside your docker folder to store all your configuration files.

Step 1: Pull the Plex Image

To start, you need to pull the Plex image from Docker Hub. Open your terminal or command prompt and run the following command:

docker pull linuxserver/plex

Step 2: Run the Container with a single command (or Step 2.1 to use docker-compose)

Now, you need to create a new container based on the Plex image. Run the following command:

docker run -d --name plex -p 32400:32400 -v /home/nicolas/docker/media/movies:/movies -v /home/nicolas/docker/media/series:/tv -v /home/nicolas/docker/plex/config:/config linuxserver/plex

Explanation of the Options:

  • `-d` runs the container in detached mode, which allows you to continue using your terminal while Plex is running.
  • `–name plex` assigns a name to the container. You can use this name to stop or restart the container later.
  • `-p 32400:32400` maps port 32400 on your host machine to port 32400 in the container. This allows you to access Plex from outside the container.
  • `-v /home/nicolas/docker/media/movies:/movies` mounts a directory on your host machine as a volume inside the container. This is where you store your movie files. Remember to replace this with your Movies folder location.
  • `-v /home/nicolas/docker/media/series:/tv` mounts a directory on your host machine as a volume inside the container. This is where you store your tv series files. Remember to replace this with your Series folder location.
  • `-v /path/to/config:/config` mounts another directory on your host machine as a volume inside the container. This is where Plex will store its configuration files.
  • Tip: You can also add your music by adding ‘-v /home/nicolas/docker/media/music:/music’ just as we did with the movies and the series and replacing the path to your music folder with the right address.

Step 2.1: Run the container using docker-compose.yml file

This is the preferred option, doing it this way will let you modify things if needed and have a configuration file to go back to.
As we usually do, we go to our /docker/plex folder and we create a Docker Compose yml file by writing on the terminal: sudo nano docker-compose.yml and we past the following:

---
services:
  plex:
    image: lscr.io/linuxserver/plex:latest
    container_name: plex
    network_mode: host
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - VERSION=docker
      - PLEX_CLAIM= #optional
    volumes:
      - /home/nicolas/docker/plex/config:/config
      - /home/nicolas/docker/plex/series:/tv
      - /home/nicolas/docker/plex/movies:/movies
- /home/nicolas/docker/plex/music:/music restart: unless-stopped

We save with CTRL+O and exit with CTRL+X

Extra: Docker-Compose file analysis

Let’s break down the `docker-compose.yml` file:

**Services:**
The first line specifies that we’re defining a single service, named `plex`.

**Image:**
The `image` directive tells Docker Compose to use the latest version of the `lscr.io/linuxserver/plex` image. This is the Plex media server container image.

**Container Name:**
The `container_name` directive specifies that we want to name this container `plex`. This can be useful for identifying and managing multiple containers in a single Compose project.

**Network Mode:**
The `network_mode` directive sets the network mode for the container. In this case, it’s set to `host`, which means that the container will use the host’s network stack instead of creating its own virtual network interface.

**Environment Variables:**
The `environment` directive defines environment variables that will be passed to the container. There are five variables defined:

* `PUID`: This is a user ID, set to 1000.
* `PGID`: This is a group ID, also set to 1000.
* `TZ`: This sets the time zone for the container, in this case, `Etc/UTC`.
* `VERSION`: This sets an environment variable named `VERSION` to the value `docker`.
* `PLEX_CLAIM`: This is an optional environment variable that allows you to claim your Plex installation. If you don’t set it, Plex will not be able to access any claimed libraries. Tip: you can do this from your https://plex.tv account settings.

**Volumes:**
The `volumes` directive mounts host directories as volumes inside the container. There are four volumes defined:

* `/home/nicolas/docker/plex/config:/config`: This mounts a directory on the host machine (`/home/nicolas/docker/plex/config`) to the `/config` directory inside the container.
* `/home/nicolas/docker/plex/series:/tv`: This mounts another directory on the host machine (`/home/nicolas/docker/plex/series`) to the `/tv` directory inside the container. This likely contains TV shows.
* `/home/nicolas/docker/plex/movies:/movies`: This mounts a third directory on the host machine (`/home/nicolas/docker/plex/movies`) to the `/movies` directory inside the container. This likely contains movies.
* `/home/nicolas/docker/plex/music:/music`: This mounts a fourth directory on the host machine (`/home/nicolas/docker/plex/music`) to the `/music` directory inside the container. This likely contains music files.

**Restart:**
The `restart` directive specifies that we want the container to restart unless it’s stopped manually (i.e., using `docker stop plex`). This ensures that the Plex media server remains running even if the host machine reboots or the container crashes.

Step 3: Start Plex

To start Plex, run the following command:

docker compose up -d

Explanation of the Options:

  • `docker compose up` runs a command inside the folder that executes the configuration in the docker-compose.yml file.
  • `-d` runs the container on detached mode.

Step 4: Enjoy!

With these steps, you should now have a running Plex media server on your system. You can access it by going to http://localhost:32400 in your web browser.