Build minimal Ubuntu 20.04 server, add ONLY OpenSSH during installation.
Watch your disk partitions! You will be using a lot (eventually), the majority will end up under /var, so crank that up, or go with one partition, just be warned.
After the base install:
ssh to box:
# I'm bad, I do it all as root
sudo su -
apt update
apt upgrade
Install Docker:
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent
sudo apt-get install software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo apt -y install mc iperf3 iptraf-ng
sudo docker run hello-world
Install Portainer
docker run -d --name portainer --restart unless-stopped -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
Links
# Portainer is on:
http://SERVER_IP:9000/
You may have to reboot the host if this is the first time through!
Beware that firewalld and iptables are all in this mess! You may have to enable ports or disable the firewall on the LAN side to get your containers to work.
If you can’t build a new container or can’t connect, reboot the box at least once before freaking out.
Portainer templates
- Open Portainer (http://SERVER_IP:9000/)
- Double click on your host
- Go to Settings
- Go to App Templates
- Select “Use External Templates”
- Paste in:
- https://raw.githubusercontent.com/SelfhostedPro/selfhosted_templates/master/Template/template.json
- Click “Save Settings”
- Go to “App Templates” in the blue bar menu
- Turn on “Show Container Templates”
Useful scripts for your Docker host:
# docker-cleanup.sh
date
df -h
docker image prune -a
docker container prune
docker system prune
date
df -h
# dockerlogs.sh
#!/bin/bash
DARKGRAY='\033[1;30m'
LIGHTRED='\033[1;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
LIGHTPURPLE='\033[1;35m'
CYAN='\033[0;36m'
COLORS=($DARKGRAY $LIGHTRED $GREEN $YELLOW $BLUE $LIGHTPURPLE $CYAN )
color_stop=$(printf '\033[0m')
size=${#COLORS[@]}
names=$(docker ps --format "{{.Names}}")
echo "tailing $names"
while read -r name
do
index=$(($RANDOM % $size))
color_start=$(printf ${COLORS[$index]})
# eval to show container name in jobs list
eval "docker logs -f --tail=5 \"$name\" | sed -e \"s/^/${color_start}[-- $name --]${color_stop} /\" &"
done <<< "$names"
function _exit {
echo
echo "Stopping tails $(jobs -p | tr '\n' ' ')"
echo "..."
# Using `sh -c` so that if some have exited, that error will
# not prevent further tails from being killed.
jobs -p | tr '\n' ' ' | xargs -I % sh -c "kill % || true"
echo "Done"
}
# On ctrl+c, kill all tails started by this script.
trap _exit EXIT
# Don't exit this script until ctrl+c or all tails exit.
wait