Setting Up Your Home Media Server (Part One)
For over 4 years, I used a 2012 X220 ThinkPad as my main system. It is a great machine if you do not consider the three times the wire on the power jack cable got disconnected. It always started with not charging at certain angles. Eventually, it will not charge at all and I am left with a brick.
The last time was over a month ago and the replacement power jack was super expensive on Amazon. Thus, I decided to solder the pins myself. The soldering went well, but the keyboard ribbon cable, which was pretty fragile, broke when I was assembling my laptop. I considered that as a sign to change my laptop, but I did not want to put the fully functional old ThinkPad away.
In this post, I want to share with you how the old ThinkPad is turned into a great home media server. The easiest way to run a home media server is to buy a Network Attached Storage (NAS) device and connect it to your router. However, you can easily convert your old PC or laptop to a home media server and use it to share your files among many devices in your home, watch movies and listen to music on Plex, and block ads with Pi-hole. My old laptop is also quite energy efficient costing around 3 cents every day. However, I would appreciate it if it was not such a huge fireplace during file transfer and downloads.
The first big question is the operating system. I am not a Linux user, mainly since our research group prefers Windows and they give us Windows systems. However, I found Linux is the best choice to build my home media server. Since I was familiar with Ubuntu distribution, I decided to install Ubuntu Server on my laptop. You can find the installation file from the Ubuntu website. I used Option 3: Manual Install, and installed the Ubuntu Server with a bootable USB stick.
My next big decision was to use Docker to install and configure the apps on my Home Media Server. You can read about Docker in their Why Docker? webpage. I used Docker because of the following reasons:
- It is much easier to configure the apps and take care of their pre-requisites or incompatibilities with Docker containers. Containers are small units of software that isolate the apps from the operating system and most reputable Home Media Server apps have extensive documentation that helps you start and configure the container.
- It is much more secure.
- You learn a lot of Docker in the process.
So after taking care of Linux Server, I installed Docker on Ubuntu using this simple installation guide. If everything works properly, you should get a Hello
message from Docker by running the following command:
$ sudo docker run hello-world
Docker does not automatically start when you boot Ubuntu, thus, we need to use systemctl
to autostart docker by the following command:
$ sudo systemctl enable docker
Next, we need to install Docker compose, which simplifies the installation of apps. With Compose, we can use Compose files to configure applications’ services once and for all. We can install Docker Compose from its Github repository or use Docker Compose documentation to install it.
During deploying the applications we want to use on Home Server, we need to use some Docker commands. This cheat sheet contains the most important commands. In my opinion, it is enough to know:
-
to remove all stopped containers and unused images
$ docker system prune
-
to remove a particular container
$ docker container rm [CONTAINER ID]
-
to get a list of all containers and find their ids
$ docker container ls -a
-
to stop a particular container
$ docker container stop [CONTAINER ID]
-
to find ids of all docker images on your system
$ docker image ls
-
to remove a docker image
$ docker image rm [CONTAINER ID]
Also, I found this tutorial very useful. It described each step more thoroughly, so if you face some problems, check it out.
How to use Docker Compose
Docker Compose uses a compose file, with .yml
extension, to pull the image and set the networks and volumes. For each app, you need to configure the Docker Compose file. Some docker containers on the docker hub have a sample of Compose file ready and you just need to change some details.
In the next part of this tutorial, I am going to explain how to install and configure the following packages on your Home Media Server:
Before ending this tutorial, I want to introduce two useful apps that you probably need to install on your Home Media Server, regardless of your use cases.
Portainer
Portainer provides a user interface to manage your docker containers. It is much easier than connecting to the server with SSH and running commands. I usually use it to stop or restart containers and check their runtime. You can find Portainer container on docker hub and a sample Docker Compose file for Portainer is:
portainer:
image: portainer/portainer
container_name: portainer
restart: always
command: -H unix:///var/run/docker.sock
ports:
- "XXXX:9000"
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
- '${USERDIR}/docker/portainer/data:/data'
- '${USERDIR}/docker/shared:/shared'
environment:
- TZ: '${TZ}'
Be mindful of the blank spaces at the beginning of each line. To configure this file for your system, you need to:
- Fill the port number
XXXX
with a free port on Linux. You want Portainer to be available at this port. - Fill
${USERDIR}
with the user directory that you want to save the Portainer data and shared file. - Fill the
${TZ}
with your local timezone (for exampleAmerica:Vancouver
)
After saving the Docker Compose file in docker-compose.yml
, run the following command to start the container:
$ docker-compose -f docker-compose.yml up -d
-d
runs the container in background mode, freeing the terminal for you. If you want to debug the process and see the logs, you can run the following command:
$ docker-compose logs -tf --tail="50" portainer
Portainer should be available at http://SYSTEM-IP:XXXX
if everything works.
Watchtower
Watchtower monitors docker containers and if their images in the Docker hub change, it will pull the new image and restart the container with the updated image. Then, you do not need to manually update any application on the Home Media Server. You can find Watchtower container on docker hub and the Docker Compose file should for Watchtower is:
watchtower:
container_name: watchtower
restart: always
image: v2tec/watchtower
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
command: --schedule "0 0 4 * * *" --cleanup
You can specify the frequency of updating by changing the schedule. In this example, containers are checked every morning at 4 AM. It also removes the old images after updating them. Save it in docker-compose.yml
and run it using the following command:
$ docker-compose -f docker-compose.yml up -d
Watchtower works in the background. You can check it with:
$ docker container ls -a
Netdata
Netdata is a free and open-source performance and health monitoring tool. I found my laptop to get very hot during some processes and I was generally curious about the CPU, RAM, and disk usage. Thus, decided to install it on my server. However, it seems that installing Netdata in a container limits its capabilities and some data is not accessible or not as detailed in a container. You can easily install it on your system running the following command:
$ sudo apt-get install netdata -y
When installed on the system, Netdata is accessible on port 19999
, so open your browser and go to this URL:
http://SYSTEM-IP:19999