Putting it all together

Using Docker, Docker-Compose, Port Forwarding, and NGinX Proxy Manager all together to host multiple servers.

Almost all of my content covers installing a free, open source, self hosted server or service.  Occasionally I cover an open source application or tool that isn't running a server.

When I cover running a server, I try to use the best tools, that are easy to utilize and deploy, and keep the management to a minimum.

Many of you are IT professionals, or are looking to become IT pros.  Others are the IT pro for your home, family, and friends.

This video is to cover some of the tools and utilities that I will likely use on 90% of my videos. I want to make this as a base level video that you can reference anytime I do new content on a tool, server, or service you want to run.  This video all on it's own is long, but if I cover this on every video, it just makes those even longer.

I'm hoping to use this video as a reference video to access whenever it's needed.

Docker and Docker Compose

Docker was confusing to me initially.  I really just didn't get it.  I didn't understand what it was.  But, at some point, it just clicked with me.

The best explanation I can give, is exactly what their logo tried to exhibit.  Docker is teh Giant Transport Ship, and your servers / services are the containers on the ship.

In reality, Docker is a virtual environment (think Virtual Box, etc) where you run servers in virtual machines that are very slimmed down to only have the most necessary pieces of software.

Docker is the Server Rack, and the Containers are the servers in the rack.

Docker-Compose is a tool to make it a bit easier to get Docker containers (especially multiple containers that need to communicate) up and running using a static configuration file.

I use the instructions at Digital Ocean for installing Docker-CE, and essentially just Google "install docker-ce on Ubuntu ".

I make a script of it, then run the script as I generally work on an LTS (Long Term Support) version of Ubuntu.

#!/bin/bash
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

## for ubuntu 18.04
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"

## for ubuntu 20.04
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce -y

## now set user as part of docker group
sudo usermod -aG docker ${USER}

## install docker-compose
sudo apt install docker-compose -y

Copy the text above into a new file. Take the 18.04, or 20.04 line based on the version of Ubuntu you are using.

Then save the file as docker_install.sh.

This will make it simpler if you will be setting up multiple physical servers or machines that you want to run docker on.

Routing of Domain Names

What a huge topic!  There are so many ways you can route traffic from a domain, but in general, I usually will route a domain to a server being hosted on Digital Ocean or SSDNodes using an A record in DNS, or I will route a domain to my home server (still using an A record, but in a special way).

A bit of additional routing knowledge is needed for hosting a server from home, and there are multiple solutions available for that as well, but my preferred solution is NGinX Proxy Manager.

Let's just pretend we have a domain called rpi-rules-the-world.com.  We don't, but we will pretend.

What I like to do is create a subdomain on my domain related to a server or web-application I'm running.  Let's say we are running a chat server like RocketChat, and we want to make it easier for our users to find our chat server.  We'll choose to call it chat.rpi-rules-the-world.com.

So, from our Domain registar (Hover, GoDaddy, Ghandi.net, etc), you'll edit the DNS for rpi-rules-the-world.com, and add a new A record called "chat".  You'll point that name to the public IP address of your server.

Once you have that working, you're essentially done.  There are still steps to make sure the site is secured with SSL, but the basics are complete.

Hosting from Home

If we want to host from Home, and you only want 1 (one) domain name for a server, then do the same thing, but know you'll have to port forward through your home router, to allow traffic to the server you run.

This can be done more safely by running something like NGinX Proxy Manager.

NGinX Proxy Manager

While this is a useful tool when you host from home, it's a useful tool for any server, hosting from anywhere.

NGinX Proxy Manager is run as a browser based GUI for setting up NGinX reverse proxied websites.

Essentially, you forwward only ports 80 and 443 on your home router, to the server where you run NGinX Proxy Manager (NPM), and allow NPM to route requests for websites / applications accross your network, or within the same docker instance.

Additionally, NPM can help you get LetsEncrypt SSL certificates for the sites you are running.

To install NPM you need to install docker and docker-compose, and create a new folder on the server you want to run it in.  Next, you'll create two files inside that folder:

  • config.json
  • docker-compose.yml

Inside the config.json file, you'll put the following:

{
  "database": {
    "engine": "mysql",
    "host": "db",
    "name": "npm",
    "user": "<your desired username>",
    "password": "<a strong password>",
    "port": 3306
  }
}

And inside the docker-compose.yml file you'll put:

version: '3'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    volumes:
      - ./config.json:/app/config/production.json
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
  db:
    image: 'jc21/mariadb-aria:10.4'
    environment:
      MYSQL_ROOT_PASSWORD: 'npm'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: '<username from config.json>'
      MYSQL_PASSWORD: '<strong password from config.json>'
    volumes:
      - ./data/mysql:/var/lib/mysql

Make sure to replace the items with < and > around it in each file, and that the username and passwords in each file match.

Now run the command:

docker-compose up -d

Give it a minute to pull down everything, and get started, and then in your browser go to the IP address of your server.  You should get a Congratulations screen.

if you go tot he IP address at port 81 (http://192.168.1.x:81), you'll be prompted to login to NPM.

Default credentials are:

username: admin@example.com
passwrod: changeme

Make sure to update the email and password, from the default values, then log out, and back in usign the new values you entered.

Now, you're ready to start proxying traffic.

If you can get the basics of what I cover in this video, all the others will be much easier to follow.

I hope this helps, and best to you all.