Setting Up Your Home Media Server (Part Two)

Shayan Fahimi
6 min readJul 4, 2020
Photo by Jens Kreuter on Unsplash

This is the second part of my tutorial on running a Media Home Server using your old PC or laptop. In the first part, I explained why it is a good idea to turn your old PC into a Home Media Server, and introduced Docker containers for a few apps. My main goal for running a Home Media Server was to simplify the process of playing videos stored on my hard drive on the TV with my XBOX and I used Plex for that. In this part, I am going to explain how to install and configure the following packages, including Plex, on your Home Media Server:

Pi-hole

Pi-hole is a network-wide ad blocking app that also provides great insight into the domains that are being visited by each device on your network. Pi-hole container on docker hub has pretty much all configuration covered. Before using my laptop, I had Pi-hole on a Raspberry-Pi connected to my router. Since I had the laptop, it was a good idea to retire the Raspberry-Pi for now. A simple Compose file for running Pi-hole looks like this:

services:
pihole:
container_name: pihole
domainname: docker
hostname: pihole
image: pihole/pihole:latest
ports:
- "53:53/tcp"
- "53:53/udp"
# - "67:67/udp"
- "XXXX:80/tcp"
- "YYYY:443/tcp"
environment:
TZ: '${TZ}'
# WEBPASSWORD: pihole
# Volumes store your data between container upgrades
volumes:
- '${USERDIR}/pihole:/etc/pihole/'
- '${USERDIR}/pihole.log:/var/log/pihole.log'
- '${USERDIR}/pihole/dnsmasq:/etc/dnsmasq.d/'
dns:
- 127.0.0.1
- 1.1.1.1
restart: unless-stopped

XXXX and YYYY are port numbers on the host machine that are free to talk to ports 80 and 443 of the Pi-hole container. Port 443 provides the sinkhole for ads that use SSL. If you want Pi-hole to act as your DHCP server, you need to uncomment 67:67/udp line, however, I recommend configuring your router instead, which is demonstrated here. If you want Pi-hole to save logs even if containers are recreated, you need to point it to a volume outside the container. Also, dns shows the DNS IPs you would like to use on Pi-hole. Save this Compose file in docker-compose.yml and run it using the following command:

$ docker-compose -f docker-compose.yml up -d

You have access to some ports on your server by default, but if you are using ports other than 80, 443, and 22 for your apps, you need to configure the firewall and enable access. It can be done by running this command:

$ sudo ufw allow [PORT]

Enter the port that you are using on the Linux machine, shown here by XXXX. With this configuration, you can access Pi-hole by opening your browser and going to this URL:

http://SYSTEM-IP:XXXX

To learn more about Pi-hole, you should take a look at their GitHub repository or their official documentation.

Plex

Plex is a client-server media player model that provides great client-side applications on your browser or for your phone and XBOX. I have personal media files, including music, movies, and some personal photos, on my hard drive. To watch movies, I had to disconnect the hard drive from my PC and connect it to the XBOX and it was not convenient. With Plex, you can easily play media on your devices, even if they are not on the same network. Plex container is developed by Linuxserver and has a complete guideline. A simple Compose file for running Plex looks like this:

services:
plex:
image: linuxserver/plex
container_name: plex
network_mode: host
environment:
- PUID=1000
- PGID=1000
- VERSION=docker
- TZ: '${TZ}'
ports:
- "XXXX:32400/tcp"
volumes:
- '${USERDIR}/plex/library:/config'
- '{$MOVIEDIR}:/movies'
- '{$SERIESDIR}:/series'
- '{$MUSICDIR}:/music'
- '{$PICSDIR}:/pictures'
restart: unless-stopped

XXXX is the port number on your host machine, Linux server, which you want to use to access Plex. PUID and PGID are user and group ID. When you are using volumes, permissions issues might arise between the host, Linux Server, and the containers. You need to ensure that the volume directories you are using on the host are owned by the same user you specify. To find your ids, you can run the command below:

$ id username

Save this Compose file in docker-compose.yml and run it using the following command:

$ docker-compose -f docker-compose.yml up -d

Like Pi-hole, you can access Plex by opening your browser and going to this URL (of course XXXX for Plex should be different from the port you are using for Pi-hole):

http://SYSTEM-IP:XXXX

If you want to enable remote access on Plex, to have access to your files on networks other than your home network or share content with your friends, you can use this article on their website. You should also enable port-forwarding on your router. Port forwarding is simpler if you use 32400 for XXXX.

CalibreWeb

CalibreWeb is an app on your browser that provides a clean interface for browsing and reading your eBooks using an existing Calibre library. So, first, you need to make a Calibre library and you can do that by installing the Calibre docker container and using the following Docker Compose file:

services:
calibre:
image: linuxserver/calibre
container_name: calibre
environment:
- PUID=1000
- PGID=1000
- TZ: '${TZ}'
volumes:
- '${USERDIR}/config:/config'
- '${BOOKSDIR}:/books'
ports:
- XXXX:8080
- YYYY:8081
restart: unless-stopped

Here, XXXX and YYYY are ports on your host machine for Calibre desktop GUI and Calibre web server GUI respectively. When you run the Compose file, Calibre will create a library in ${USERDIR}/config. This should be imported in Calibreweb. You can find the Calibreweb container on Dockerhub and it has a manual on Github. The following Compose file works well:

services:
calibre-web:
image: linuxserver/calibre-web
container_name: calibre-web
environment:
- PUID=1000
- PGID=1000
- TZ: '${TZ}'
- DOCKER_MODS=linuxserver/calibre-web:calibre
volumes:
- ${USERDIR}/config:/config
- '{$BOOKLIBRARY}:/books'
ports:
- XXXX:8083
restart: unless-stopped

XXXX is the port you want to use to access Calibreweb on your Home Server. {$BOOKLIBRARY} is a local path on your Linux machine that contains Calibre books and the necessary metadata.db which holds all collected meta-information of the books. For example, if you have Calibre config stored in ${USERDIR}/config, then {$BOOKLIBRARY} should look like ${USERDIR}/config/Calibre Library.

Samba

If you are using Windows and like to access files on your Homeserver, you must install Samba on it. Unfortunately, the installation was not as user-friendly as other packages. Samba Container is developed by dperson on Dockerhub and a simple Docker Compose file looks like this:

services:
samba:
image: dperson/samba
container_name: samba
restart: always
stdin_open: true
tty: true
environment:
TZ: '${TZ}'

# advertise shares, default: true, or false (open ports 137, 138)
NMBD: "true"

# add a single user. If you need more, use command instead of environment
# required arg: "<username>;<passwd>"
# <username> for user
# <password> for user
# [ID] for user, default: ""
# [group] for user, default: ""
USER: "yourname;password"

# set the UID for the samba share, default: ""
USERID: "0"

# set the GID for the samba share, default: ""
GROUPID: "0"

# add a single share. If you need more, use command instead of environment
# required arg: "<name>;</path>"
# <share_name>;
# <path_to_share>;
# [browsable] default:'yes' or 'no';
# [read_only] default:'yes' or 'no';
# [guest]: default: 'yes' or 'no';
# [users]: default: 'all' or list of allowed users;
# [admins] default: 'none' or list of admin users;
# [writelist] default: 'none' or list of users that can write to read-only share;
# [comment] default: 'none' or description of share
SHARE: "sharename;/mnt;yes;no;no;yourname;'none';'none';'Homeserver"

# workgroup/domain name for share default: "MYGROUP"
WORKGROUP: "Homeserver"

# if set, disables recycle bin for shares
RECYCLE: ""

# if set, disables SMB2 minimum version
# SMB: ""

networks:
- default
ports:
- "137:137/udp" # required to advertise shares (NMBD)
- "138:138/udp" # required to advertise shares (NMBD)
- "139:139/tcp" # default smb port
- "445:445/tcp" # default smb port
read_only: false
tmpfs:
- /tmp
volumes:
- {$MOUNTDIR}:/mnt:z # :z allows share to be used by multiple containers

I decided to keep the ports the same since other devices cannot find the Samba server if you change the ports. When you run the container, you should be able to access the files in {$MOUNTDIR} by typing the following address in Windows Explorer:

\\SYSTEM-IP\sharename

You can also map this SMB network drive using this article on the Windows support website.

Heimdall

Last but not least, Heimdall makes navigating through your Home Server applications much easier. By now, you probably have some applications installed and each of them is accessible through a different port. It is not easy to remember them every time you need to quickly access Portainer or Plex. So, Heimdall makes a dashboard for all the web applications and organizes them on your browser.

Heimdall Github and Heimdall Container are great resources. The following simple Docker Compose file runs Heimdall Container on your Home Server:

heimdall:
container_name: heimdall
restart: always
image: linuxserver/heimdall:latest
volumes:
- '${USERDIR}/config:/config'
- '${USERDIR}/shared:/shared'
ports:
- "XXXX:80"
environment:
- PUID=1000
- PGID=127
- TZ='${TZ}'

If you use ports other than 80 for XXXX, you will not see the Heimdall dashboard simply by typing your Home Server IP in the browser.

Originally published at https://shfahimi.net on July 4, 2020.

--

--