Fix Directory Hardcodes, Documentation Improvements (#10)
* Improve the main crontab example. * Remove /opt/Docker hardcodes. * Add periods. * Improve readability. * Begin removing hardcoded path from the bin files. * Update main README to no longer enforce hardcoded path. Other improvements. * Add the load folder with a README. * Add load folder and its README. * Improve reverse proxy text files. * Switch to tabs. * Update all scripts for tabs, DOCKER_HOME, and comments. * Let users know the directory choice is optional. * Fix environment file. * Add more details for the reverse proxy load balancing. * Don't actually listen for postgres. * Fix comments on source file. * Be more explicit on the pathing.
This commit is contained in:
parent
e383520ebb
commit
8602f7ada2
4
.gitignore
vendored
4
.gitignore
vendored
@ -14,8 +14,8 @@ Config/ReverseProxy/config/hosts/*
|
|||||||
Config/ReverseProxy/config/load.conf.d/*
|
Config/ReverseProxy/config/load.conf.d/*
|
||||||
Config/ReverseProxy/config/mail.conf.d/*
|
Config/ReverseProxy/config/mail.conf.d/*
|
||||||
|
|
||||||
# Ignore downloaded mail server files
|
# Ignore downloaded mail server files.
|
||||||
Config/MailServer/setup.sh
|
Config/MailServer/setup.sh
|
||||||
|
|
||||||
# Ignore any private key information
|
# Ignore any private key information.
|
||||||
private.key
|
private.key
|
||||||
|
@ -13,13 +13,15 @@ product's self-built solutions can be found below.
|
|||||||
git clone https://github.com/Hyperling/docker $PROJECT_DIR
|
git clone https://github.com/Hyperling/docker $PROJECT_DIR
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Add your Afraid DNS account key to $PROJECT_DIR/Config/DynamicDNS/private.key
|
1. Add your user key to `$PROJECT_DIR/Config/DynamicDNS/private.key`. The key can
|
||||||
Account key can be found [here](https://freedns.afraid.org/dynamic/v2/).
|
be found on [this page](https://freedns.afraid.org/dynamic/v2/) after signing in.
|
||||||
|
|
||||||
1. Add this line to the system's cron scheduling using a command like `crontab -e`.
|
1. Add this line to the system's cron scheduling using a command like `crontab -e`.
|
||||||
|
The sleep waits anywhere from 0 to 55 minutes due to the
|
||||||
|
[Random/10](https://tldp.org/LDP/abs/html/randomvar.html).
|
||||||
|
|
||||||
```
|
```
|
||||||
5 * * * * $PROJECT_DIR/Config/DynamicDNS/update_dns.sh
|
@hourly sleep $(( $RANDOM / 10 )); $PROJECT_DIR/Config/DynamicDNS/update_dns.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
### TESTING
|
### TESTING
|
||||||
@ -61,6 +63,6 @@ and preferably add a 30-45 second sleep so that you do not hit near :00 seconds.
|
|||||||
|
|
||||||
### No-IP.org Instructions
|
### No-IP.org Instructions
|
||||||
|
|
||||||
Please see this guide on installing the Dynamic Update Client (DUC).
|
Please see the official guide on installing the Dynamic Update Client (DUC).
|
||||||
|
|
||||||
https://my.noip.com/dynamic-dns/duc
|
https://my.noip.com/dynamic-dns/duc
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Nextcloud configuration.
|
# Nextcloud configuration.
|
||||||
# This is a revised version of the original work here:
|
# This is a revised version of the original work here:
|
||||||
# https://hub.docker.com/_/nextcloud
|
# https://hub.docker.com/_/nextcloud
|
||||||
|
|
||||||
# Changelog:
|
# Changelog:
|
||||||
@ -13,7 +13,7 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
|
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
|
||||||
volumes:
|
volumes:
|
||||||
- /opt/Docker/Volumes/Nextcloud/mariadb:/var/lib/mysql
|
- ../../Volumes/Nextcloud/mariadb:/var/lib/mysql
|
||||||
environment:
|
environment:
|
||||||
- MYSQL_ROOT_PASSWORD=ChangeMe
|
- MYSQL_ROOT_PASSWORD=ChangeMe
|
||||||
- MYSQL_DATABASE=nextcloud
|
- MYSQL_DATABASE=nextcloud
|
||||||
@ -28,11 +28,10 @@ services:
|
|||||||
links:
|
links:
|
||||||
- db
|
- db
|
||||||
volumes:
|
volumes:
|
||||||
- /opt/Docker/Volumes/Nextcloud/nextcloud:/var/www/html
|
- ../../Volumes/Nextcloud/nextcloud:/var/www/html
|
||||||
environment:
|
environment:
|
||||||
- MYSQL_DATABASE=nextcloud
|
- MYSQL_DATABASE=nextcloud
|
||||||
- MYSQL_USER=nc
|
- MYSQL_USER=nc
|
||||||
- MYSQL_PASSWORD=changeme
|
- MYSQL_PASSWORD=changeme
|
||||||
- MYSQL_HOST=db
|
- MYSQL_HOST=db
|
||||||
- PHP_UPLOAD_LIMIT=5G
|
- PHP_UPLOAD_LIMIT=5G
|
||||||
|
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
# Upstream Host Configuration
|
# Upstream Host Configuration
|
||||||
For systems which do not resolve well such as ignoring `/etc/hosts`.
|
For systems which do not resolve well such as ignoring `/etc/hosts`.
|
||||||
|
|
||||||
|
@ -5,4 +5,3 @@ upstream example-proxy-site {
|
|||||||
#server 127.0.0.1:8080;
|
#server 127.0.0.1:8080;
|
||||||
server hyperling.com;
|
server hyperling.com;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
# HTML Sites
|
# HTML Sites
|
||||||
If the reverse proxy also serves static HTML sites,
|
If the reverse proxy also serves static HTML sites, the root directories of each
|
||||||
the root directories of each can be placed here.
|
can be placed here. Then in `../conf.d` add a file which points the domain to
|
||||||
Then in `../conf.d` add a file which points the domain to the HTML web root,
|
the HTML web root, such as `/etc/nginx/html/www.website.name`. An example for
|
||||||
such as `/etc/nginx/html/www.website.name`.
|
this exists called `html.example.com`. It should be fairly easy to recreate for
|
||||||
An example for this exists called `html.example.com`.
|
another website.
|
||||||
It should be fairly easy to recreate for another website.
|
|
||||||
|
8
Config/ReverseProxy/config/load.conf.d/README.md
Normal file
8
Config/ReverseProxy/config/load.conf.d/README.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Load Balancing Files
|
||||||
|
Allow requests coming to this server to be spread amongst multiple servers based
|
||||||
|
on port number. It does not seem possible to spread them based on `server_name`
|
||||||
|
or other directives like a reverse proxy. The server simply listens on the port
|
||||||
|
then runs through the upstream list to determine the destination.
|
||||||
|
|
||||||
|
## Official Documentation
|
||||||
|
http://nginx.org/en/docs/stream/ngx_stream_core_module.html
|
15
Config/ReverseProxy/config/load.conf.d/example.com
Normal file
15
Config/ReverseProxy/config/load.conf.d/example.com
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Example of how to load balance 4 Postgres servers for example.com. Since this
|
||||||
|
# does not act under a reverse proxy situation, code is commented so that the
|
||||||
|
# container does not needlessly start listening on the port.
|
||||||
|
|
||||||
|
#upstream postgres_servers {
|
||||||
|
# server 1.2.3.1:5432;
|
||||||
|
# server 1.2.3.2:5432;
|
||||||
|
# server 1.2.3.3:5432;
|
||||||
|
# server 1.2.3.4:5432;
|
||||||
|
#}
|
||||||
|
#
|
||||||
|
#server {
|
||||||
|
# listen 5432;
|
||||||
|
# proxy_pass postgres_servers;
|
||||||
|
#}
|
@ -66,12 +66,17 @@ http {
|
|||||||
include /etc/nginx/conf.d/*;
|
include /etc/nginx/conf.d/*;
|
||||||
}
|
}
|
||||||
|
|
||||||
# TBD, going live with HTTP first.
|
## TBD.
|
||||||
mail {
|
mail {
|
||||||
## Reverse Proxied Mail Server Configurations ##
|
## Reverse Proxied Mail Server Configurations ##
|
||||||
#include /etc/nginx/mail.conf.d/*;
|
#include /etc/nginx/mail.conf.d/*;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## Under Experimentation
|
||||||
|
# So far does not seem like server_name works, only listen, so not useful as a
|
||||||
|
# reverse proxy. Such as 2 Postgres servers needing traffic from different
|
||||||
|
# domains, or two SMTP servers on the same IP serving two different domains.
|
||||||
|
# Those possibilities do not seem to exist here, unfortunately.
|
||||||
stream {
|
stream {
|
||||||
## Service Forwarding and Load Balancing ##
|
## Service Forwarding and Load Balancing ##
|
||||||
# If this supports the `listen` and `server_name` directives then this may
|
# If this supports the `listen` and `server_name` directives then this may
|
||||||
|
42
README.md
42
README.md
@ -1,21 +1,28 @@
|
|||||||
# My Docker Setup
|
# My Docker Setup
|
||||||
Scripting my way into the Docker world.
|
Scripting my way into the Docker world. I was unable to find a good tutorial on
|
||||||
I was unable to find a good tutorial on using and managing containers so this is what made sense to me based on practice with `docker-compose`.
|
using and managing containers so this is what made sense to me based on practice
|
||||||
I am still new to Docker and am likely to make mistakes, but you're welcome to learn with me. ;)
|
with `docker-compose`. I am still new-ish to Docker and am likely to make
|
||||||
|
mistakes, but you're welcome to learn with me. ;)
|
||||||
|
|
||||||
## Disclaimer
|
## Disclaimer
|
||||||
Currently the project only focuses on `apt` based operating systems.
|
Currently the project only focuses on `apt` based operating systems.
|
||||||
|
|
||||||
|
## Other README's
|
||||||
|
Each `./Config/PROJECT/` folder also contains its own README file with specific
|
||||||
|
information to running that sub project. This file's job is to cover the general
|
||||||
|
Docker installation. The others then contain details on their program setup.
|
||||||
|
|
||||||
## How To Use
|
## How To Use
|
||||||
Most of these commands benefit from being root. Something like a `sudo su -` if you feel comfortable with it.
|
Most of these commands benefit from being root. Something like a `sudo su -` if
|
||||||
Otherwise be aware that using sudo may cause file permission conflicts when interacting with the configuration files and folders.
|
you feel comfortable with it. Otherwise be aware that using sudo may cause file
|
||||||
|
permission conflicts when interacting with the configuration files and folders.
|
||||||
|
|
||||||
Install the project dependencies.
|
Install the project dependencies.
|
||||||
```
|
```
|
||||||
apt install git bash
|
apt install git bash
|
||||||
```
|
```
|
||||||
|
|
||||||
Clone the project.
|
Clone the project. You may choose anywhere, but `/opt/Docker` is recommended.
|
||||||
```
|
```
|
||||||
git clone https://github.com/hyperling/docker /opt/Docker
|
git clone https://github.com/hyperling/docker /opt/Docker
|
||||||
```
|
```
|
||||||
@ -25,7 +32,7 @@ Load the environment variables.
|
|||||||
source /opt/Docker/source.env
|
source /opt/Docker/source.env
|
||||||
```
|
```
|
||||||
|
|
||||||
Install docker to the system.
|
Install docker to the system using the official repos.
|
||||||
```
|
```
|
||||||
install.sh
|
install.sh
|
||||||
```
|
```
|
||||||
@ -50,19 +57,24 @@ Cross your fingers and hope to profit!
|
|||||||
## Folders
|
## Folders
|
||||||
|
|
||||||
### Config
|
### Config
|
||||||
Compose projects are set up here. Each folder should have a `docker-compose.yml` file set up.
|
Compose projects are set up here. Each folder should have a `docker-compose.yml`
|
||||||
|
file set up.
|
||||||
|
|
||||||
### Volumes
|
### Volumes
|
||||||
The data of the files go here if the Config is done correctly.
|
The data of the files go here if the Config is done correctly. I think this
|
||||||
I think this should be easier to remember than `/var/lib/docker/volumes` when it comes time for migrations.
|
should be easier to remember than `/var/lib/docker/volumes` when it comes time
|
||||||
Hopefully all that'd be needed is to rsync `/opt/Docker` and run `install.sh` and then `start.sh` on the new server.
|
for migrations. Hopefully all that'd be needed is to rsync `/opt/Docker` and run
|
||||||
That's my opinion though, if someone else uses this then they are welcome to place it where they'd like.
|
`install.sh` and then `start.sh` on the new server. You are welcome to use a
|
||||||
|
directory other than `/opt/Docker`, this project is location agnostic.
|
||||||
|
|
||||||
### bin
|
### bin
|
||||||
Scripts to help make life easier. Some are pretty basic, but others do nice things like handle the container IDs.
|
Scripts to help make life easier. Some are pretty basic, but others do nice
|
||||||
|
things like handle the container IDs.
|
||||||
* `install.sh` : Install dependencies on a new server with apt.
|
* `install.sh` : Install dependencies on a new server with apt.
|
||||||
* `create.sh` : Create a new folder with the needed yml file.
|
* `create.sh` : Create a new folder with the needed yml file.
|
||||||
* `start.sh` : Start all compose containers.
|
* `start.sh` : Start all compose containers.
|
||||||
* `stop.sh` : Stop all compose containers.
|
* `stop.sh` : Stop all compose containers.
|
||||||
* `get_logs.sh` : Create log files rather than using the `docker log` command or searching in /var/whatever.
|
* `get_logs.sh` : Create log files rather than using the `docker log` command or
|
||||||
* `uninstall.sh` : If something goes wrong and you'd like to start from scratch without provisioning a new server then this should do the job.
|
searching in /var/whatever.
|
||||||
|
* `uninstall.sh` : If something goes wrong and you'd like to start from scratch
|
||||||
|
without provisioning a new server then this should do the job.
|
||||||
|
@ -3,7 +3,17 @@
|
|||||||
# Create new container template.
|
# Create new container template.
|
||||||
# usage: create.sh PROJECT_NAME
|
# usage: create.sh PROJECT_NAME
|
||||||
|
|
||||||
source /opt/Docker/source.env
|
## Setup ##
|
||||||
|
|
||||||
|
DIR="`dirname $0`"
|
||||||
|
PROG=`basename $0`
|
||||||
|
if [[ $DIR == *"."* ]]; then
|
||||||
|
DIR="`pwd`"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z $DOCKER_HOME ]]; then
|
||||||
|
DOCKER_HOME="$DIR/.."
|
||||||
|
fi
|
||||||
|
|
||||||
## Validation ##
|
## Validation ##
|
||||||
|
|
||||||
@ -26,10 +36,9 @@ file="$dir/docker-compose.yml"
|
|||||||
|
|
||||||
cd $DOCKER_HOME
|
cd $DOCKER_HOME
|
||||||
mkdir -pv "$dir"
|
mkdir -pv "$dir"
|
||||||
[[ ! -f "$file" ]] && echo -e "# Comment.\nservices:\n" >> "$file" ||
|
[[ ! -f "$file" ]] && echo -e "# Comment.\nservices:\n" >> "$file" ||
|
||||||
echo "File already exists, leaving contents alone."
|
echo "File already exists, leaving contents alone."
|
||||||
echo "${file}:"
|
echo "${file}:"
|
||||||
cat "$file"
|
cat "$file"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
@ -3,21 +3,31 @@
|
|||||||
# Put active logs into files for analysis.
|
# Put active logs into files for analysis.
|
||||||
# usage: get_logs.sh
|
# usage: get_logs.sh
|
||||||
|
|
||||||
source /opt/Docker/source.env
|
## Setup ##
|
||||||
|
|
||||||
|
DIR="`dirname $0`"
|
||||||
|
PROG=`basename $0`
|
||||||
|
if [[ $DIR == *"."* ]]; then
|
||||||
|
DIR="`pwd`"
|
||||||
|
fi
|
||||||
|
if [[ -z $DOCKER_HOME ]]; then
|
||||||
|
DOCKER_HOME="$DIR/.."
|
||||||
|
fi
|
||||||
|
|
||||||
dir=logs
|
dir=logs
|
||||||
date_format="+%Y%m%d-%H%M%S"
|
date_format="+%Y%m%d-%H%M%S"
|
||||||
|
|
||||||
|
## Main ##
|
||||||
|
|
||||||
cd $DOCKER_HOME
|
cd $DOCKER_HOME
|
||||||
mkdir -p $dir
|
mkdir -p $dir
|
||||||
docker ps | while read container_id image_name other; do
|
docker ps | while read container_id image_name other; do
|
||||||
image_name=${image_name##*/}
|
image_name=${image_name##*/}
|
||||||
echo $container_id $image_name
|
echo $container_id $image_name
|
||||||
docker inspect $container_id 1>/dev/null 2>&1 &&
|
docker inspect $container_id 1>/dev/null 2>&1 &&
|
||||||
docker logs $container_id 1>${dir}/${image_name}.log.`date $date_format` 2>&1
|
docker logs $container_id 1>${dir}/${image_name}.log.`date $date_format` 2>&1
|
||||||
done
|
done
|
||||||
|
|
||||||
chmod -R 755 $dir
|
chmod -R 755 $dir
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
@ -4,7 +4,16 @@
|
|||||||
# Original comands came from here: https://docs.docker.com/engine/install/debian/
|
# Original comands came from here: https://docs.docker.com/engine/install/debian/
|
||||||
# usage: install.sh
|
# usage: install.sh
|
||||||
|
|
||||||
## Variables ##
|
## Setup ##
|
||||||
|
|
||||||
|
DIR="`dirname $0`"
|
||||||
|
PROG=`basename $0`
|
||||||
|
if [[ $DIR == *"."* ]]; then
|
||||||
|
DIR="`pwd`"
|
||||||
|
fi
|
||||||
|
if [[ -z $DOCKER_HOME ]]; then
|
||||||
|
DOCKER_HOME="$DIR/.."
|
||||||
|
fi
|
||||||
|
|
||||||
os=`grep ^'NAME=' /etc/os-release`
|
os=`grep ^'NAME=' /etc/os-release`
|
||||||
pkgmgr=""
|
pkgmgr=""
|
||||||
|
24
bin/start.sh
24
bin/start.sh
@ -3,16 +3,26 @@
|
|||||||
# Start all containers.
|
# Start all containers.
|
||||||
# usage: start.sh
|
# usage: start.sh
|
||||||
|
|
||||||
source /opt/Docker/source.env
|
## Setup ##
|
||||||
|
|
||||||
|
DIR="`dirname $0`"
|
||||||
|
PROG=`basename $0`
|
||||||
|
if [[ $DIR == *"."* ]]; then
|
||||||
|
DIR="`pwd`"
|
||||||
|
fi
|
||||||
|
if [[ -z $DOCKER_HOME ]]; then
|
||||||
|
DOCKER_HOME="$DIR/.."
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Main ##
|
||||||
|
|
||||||
cd $DOCKER_HOME/Config
|
cd $DOCKER_HOME/Config
|
||||||
for dir in `ls`; do
|
for dir in `ls`; do
|
||||||
[ -d $dir ] && cd $dir || continue
|
[ -d $dir ] && cd $dir || continue
|
||||||
pwd
|
pwd
|
||||||
[ -e Dockerfile ] && docker compose build
|
[ -e Dockerfile ] && docker compose build
|
||||||
[ -e docker-compose.yml ] && docker compose up -d
|
[ -e docker-compose.yml ] && docker compose up -d
|
||||||
cd ..
|
cd ..
|
||||||
done
|
done
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
22
bin/stop.sh
22
bin/stop.sh
@ -3,15 +3,25 @@
|
|||||||
# Stop all containers.
|
# Stop all containers.
|
||||||
# usage: stop.sh
|
# usage: stop.sh
|
||||||
|
|
||||||
source /opt/Docker/source.env
|
## Setup ##
|
||||||
|
|
||||||
|
DIR="`dirname $0`"
|
||||||
|
PROG=`basename $0`
|
||||||
|
if [[ $DIR == *"."* ]]; then
|
||||||
|
DIR="`pwd`"
|
||||||
|
fi
|
||||||
|
if [[ -z $DOCKER_HOME ]]; then
|
||||||
|
DOCKER_HOME="$DIR/.."
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Main ##
|
||||||
|
|
||||||
cd $DOCKER_HOME/Config
|
cd $DOCKER_HOME/Config
|
||||||
for dir in `ls`; do
|
for dir in `ls`; do
|
||||||
[ -d $dir ] && cd $dir || continue
|
[ -d $dir ] && cd $dir || continue
|
||||||
pwd
|
pwd
|
||||||
[ -e docker-compose.yml ] && docker compose down
|
[ -e docker-compose.yml ] && docker compose down
|
||||||
cd ..
|
cd ..
|
||||||
done
|
done
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
@ -9,4 +9,3 @@ rm -v /etc/apt/sources.list.d/docker.list &&
|
|||||||
rm -rfv /var/lib/docker
|
rm -rfv /var/lib/docker
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
# 2022-09-25 Hyperling
|
# 2022-09-25 Hyperling
|
||||||
# Script to update a docker compose image.
|
# Script to update a docker compose image.
|
||||||
|
|
||||||
docker compose down
|
docker compose down
|
||||||
docker compose pull &&
|
docker compose pull &&
|
||||||
|
docker compose build &&
|
||||||
docker compose up -d &&
|
docker compose up -d &&
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
echo "ERROR: Did not update or start correctly." &&
|
echo "ERROR: Did not update or start correctly." &&
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
22
source.env
Normal file → Executable file
22
source.env
Normal file → Executable file
@ -1,19 +1,7 @@
|
|||||||
#!/bin/bash
|
|
||||||
# Provide any necessary project variables.
|
# Provide any necessary project variables.
|
||||||
# Script is a shell file so that the paths can be relative.
|
# Needs run in the current shell environment, such as:
|
||||||
|
# source /PATH_TO_GIT_PROJECT/source.env
|
||||||
|
|
||||||
DIR=`dirname $0`
|
export DOCKER_HOME="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||||
if [[ $DIR == \.* ]]; then
|
export DOCKER_PATH="$DOCKER_HOME/bin"
|
||||||
DIR=`pwd`
|
export PATH="$DOCKER_PATH:$PATH"
|
||||||
fi
|
|
||||||
|
|
||||||
# Some projects are hard-coded to use /opt/Docker/Volumes so display a notice
|
|
||||||
# until they are updated to be directory agnostic. Will help with testing!
|
|
||||||
PREFERRED_HOME="/opt/Docker"
|
|
||||||
if [[ $DIR != $PREFERRED_HOME ]]; then
|
|
||||||
echo "WARNING: Preferred home is $PREFERRED_HOME but using $DIR." >&2
|
|
||||||
fi
|
|
||||||
|
|
||||||
DOCKER_HOME=$DIR
|
|
||||||
DOCKER_PATH=$DOCKER_HOME/bin
|
|
||||||
PATH=$DOCKER_PATH:$PATH
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user