LINUX, FOSS AND LIBRARY TECHNOLOGY ENTHUSIAST

Wednesday, January 4, 2023

Install Docker, Docker-Compose and NGinx Proxy Manager on Debian

0 comments
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.

Official documentation on installing Docker 

I have created a script that includes every commands and steps, you just need to run the script as root


Or Manually create a bash file

nano docker_install.sh

#!/bin/bash

## update & upgrade Debian
sudo apt update && sudo apt upgrade -y

## install few required packages not available with Debian by default. 
sudo apt install -y software-properties-common dirmngr file-roller ca-certificates curl gnupg lsb-release

## add Docker’s official GPG key:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

## set up the repository:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

## update
sudo apt update

## install Docker Engine
apt-cache policy docker-ce
sudo apt install -y docker-ce

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

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

save the file

Run the bash file

sudo ./docker_install.sh

This process will add docker in the server

Verify the Docker installation and version.

sudo docker version

Enable the Docker service to start up on system boot.

sudo systemctl enable docker

Check the Docker service status.

sudo systemctl status docker

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
mkdir npm
cd npm

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

{
  "database": {
    "engine": "mysql",
    "host": "db",
    "name": "npm",
    "user": "npm",
    "password": "npm",
    "port": 3306
  }
}

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

version: "3"
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      # These ports are in format <host-port>:<container-port>
      - '80:80' # Public HTTP Port
      - '443:443' # Public HTTPS Port
      - '81:81' # Admin Web Port
      # Add any other Stream port you want to expose
      # - '21:21' # FTP
    environment:
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "npm"
      DB_MYSQL_PASSWORD: "npm"
      DB_MYSQL_NAME: "npm"
      # Uncomment this if IPv6 is not enabled on your host
      DISABLE_IPV6: 'true'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db

  db:
    image: 'jc21/mariadb-aria:latest'
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: 'npm'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: 'npm'
    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.

No comments:

Post a Comment