Laying the "building blogs".

Learn how to get a blog just like this one spun up in the time it takes to drink a cup of coffee, have breakfast, walk your dog, wash your hands, look at a wall, and do a full workout! Quick right? Right??

Laying the "building blogs".

The "Genius" Idea

After finishing setting up my blog I wondered, "What topic should I make my first post about?" And it hit me, why not write my first post about how I got it up and running on my own personal server?

I intend on writing up on article about self-hosting services and home labs but to spare you the long-winded speech here's a quick rundown paraphrased from what Techno Tim says in his What is a HomeLab and How Do I get Started? video: "Home labbing" is the practice of setting up a small IT infrastructure in your home to experiment with and learn new technologies. It allows you to learn and build new technical skills in a safe environment without the risk of breaking anything important. It can be used for personal projects (like this one), self-learning, or as a hobby.

Let's get into the thick of it now.

Proxmox (OS)

Starting with the underlying infrastructure. I have a Dell Optiplex 7040M which is a mini-PC with low power consumption (about 60w or so). This is important since it will be running 24/7. The OS I went with is Proxmox which specializes in virtual machines and containerization and is perfect for a home lab trying to run a variety of microservices (yes even a Minecraft server) or even just for testing out different operating systems. On Proxmox I created an LXC (Linux Container) with a Debian base. LXCs are useful as they are much more lightweight than a full virtual machine running Ubuntu.

Why run in an LXC rather than a regular VM you may ask? ReadySpace explains it in a direct and high-level way.

LXC containers are lightweight, resource-efficient, and have faster startup times. While VMs provide a higher level of isolation and run separate operating systems.

Docker (Containerization)

Since we are going with Docker to host our microservices and it will be running on an LXC which is a container in itself we need to enable container nesting on our LXC to ensure there are no issues. After configuring the Proxmox LXC with Debian, allocating the proper resources to it, and enabling nested containers (I'll probably make a mini tutorial on LXCs later), we can run a full update of Ubuntu and install Docker:

$ sudo apt update && sudo apt upgrade -y

update the ubuntu install on the container

$ sudo apt install docker.io
$ sudo systemctl enable docker
$ sudo systemctl start docker
$ sudo systemctl status docker

install Docker, start it, and check the status of the service.

Once Docker was installed and running I used a simple Docker compose file found on the Ghost image repository in Docker Hub to spin up the necessary containers which are the Ghost service and a MYSQL database.

Ghost is an open-source blogging web application that you can use and customize to your liking! It is straightforward to use for the average tech-oriented person.

First I created the compose on my LXC

$ sudo nano ghost-compose.yml

creates a file called ghost-compose.yml using the nano text editor\

Then I pasted the compose into my newly created file. I recommend adjusting the port and database credentials to improve your security.

version: '3.1'

services:

  ghost:
    image: ghost:5-alpine
    restart: always
    ports:
      - 8080:2368
    environment:
      # see https://ghost.org/docs/config/#configuration-options
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: example
      database__connection__database: ghost
      # this url value is just an example, and is likely wrong for your environment!
      url: http://localhost:8080
      # contrary to the default mentioned in the linked documentation, this image defaults to NODE_ENV=production (so development mode needs to be explicitly specified if desired)
      #NODE_ENV: development
    volumes:
      - ghost:/var/lib/ghost/content

  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    volumes:
      - db:/var/lib/mysql

volumes:
  ghost:
  db:

ghost-compose.yml

After doing so I ran the following command to spin up the resources from the compose file:

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

spins up the containers in detached mode

With all this done you have a Ghost instance now officially running on your server! In this case port 8080.

Cloudflare Tunnelling (Networking)

Now that the server is up you need to share this service with the rest of the world over the internet. I have found that ironically the easiest way is possibly the most secure way, this is not usually the case. But rather than going through the process of opening a port on your home network, mapping it to the Ghost service and then mapping that to a domain, I have found Cloudflare Tunnels to be the most efficient solution of getting a self-hosted service on the web.

Cloudflare tunnels is another service that I would like to dive deeper into in my future posts. But for the purposes of this project, it is a self-hosted microservice that exchanges data from another web application hosted in the same network to Cloudflare servers. This exchange is encrypted and does not require an opening of any port on your home network.

You will need to either purchase a domain from Cloudflare or connect the DNS servers of your domain to Cloudflare in order for this to work. I also decided to run the Cloudflare tunnel in a Docker container by running the following command provided to me by Cloudflare:

$ sudo docker run cloudflare/cloudflared:latest tunnel --no-autoupdate run --token 

I have removed the token as each tunnel will have a unique token per domain

This spins up a cloudflared container which is now the tunnel between your home lab and Cloudflare's servers.

At this point you can configure the Public Hostname option in Cloudflare to point to the exact IP and Port of the Ghost service and have it serve the data to the web through your domain!

Fin.

By this point you should have a your Ghost blog up and running on the internet. I will create more posts in the future regarding the details of Proxmox, Ghost, Cloudflare, and Docker but for now this high level explanation of getting Ghost up and running should do the trick for the average Linux user with containerization experience.

I know this post had its highs and lows in regards to details of the steps but I'll have more uniformity when it comes to in-depth or surface-level posts moving forward.