I had an old PC sitting around doing nothing and I wanted a home server. After researching and looking up how to do things I got to work on it. I wanted an easy way to host my own game servers for games like minecraft, services like a youtube proxy or a RSS-feed and many more. But what I wanted most was a NextCloud server. I had to learn how to use Docker and Docker networking in such a way that it remained secure and accessible within my network, only by devices that we allowed. Everything should also be easily reversible or removable if we stop playing a game or a self-hosted service stops working. Docker is perfect for this.
After all that I have to say I love Docker and I really like Nextcloud. Once you learned how to set it up and use it, it was easy. You may notice that I have left out a lot of the security stuff, apart from the firewall. This is because every configuration will be different for everyone, as no-one has the same network, devices and/or needs. Also, I will not be discussing anything security related below. Security first, and making sure that everyone in the security department is doing their homework, and not just copying commands from someone else's documentation without knowing what they are doing.
Note1: "*" = Some kind of personal data.
Note2: Nextcloud 26 is used because many applications are not ready for 27.
Note3: As stated above, information about security and how to access the server from the outside is not mentioned/removed in this blog post.
Soooo.... This is how I had set up the basic stuff:
Installing a Linux-Server.
Getting the IP of the new Server.
ip addr
SSH onto it.
ssh *******@192.168.**.**
Setting up a static IP.
sudo nano /etc/netplan/00-installer-config.yaml
Loading the new config
sudo netplan apply
Check that your Internet access is still working.
ping 1.1.1.1
Setting time.
sudo timedatectl set-timezone ******/*******
sudo timedatectl set-local-rtc 1
Adding Docker to the Server.
sudo add-apt-repository universe
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin git docker-compose
sudo docker run hello-world
Setting up the Firewall
sudo apt install ufw
sudo ufw allow ssh
sudo ufw enable
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload
sudo ufw status verbose
sudo wget -O /usr/local/bin/ufw-docker https://github.com/chaifeng/ufw-docker/raw/master/ufw-docker
sudo chmod +x /usr/local/bin/ufw-docker
ufw-docker install
sudo systemctl restart ufw
sudo reboot
Preparing a RAID (Highly recommended!): [https://www.digitalocean.com/community/tutorials/how-to-create-raid-arrays-with-mdadm-on-ubuntu-22-04].
lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT
sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda /dev/sdb
y
cat /proc/mdstat
The command above shows the progress of the raid creation. DON'T REBOOT UNTIL IT'S DONE! You can continue to set everything up, just DON'T reboot.
sudo mkfs.ext4 -F /dev/md0
sudo mkdir -p /mnt/md0
sudo mount /dev/md0 /mnt/md0
df -h -x devtmpfs -x tmpfs
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
Make a backup of the the "mdadm.conf" file.
sudo update-initramfs -u
echo '/dev/md0 /mnt/md0 ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab
sudo nano /etc/fstab
Preparing the Folders.
sudo mkdir /home/*******/nextcloud
sudo mkdir /mnt/md0/nextcloud
sudo mkdir /mnt/md0/nextcloud/data
sudo mkdir /mnt/md0/nextcloud/db
Creating the compose file.
nano /home/*******/nextcloud/docker-compose.yml
Creating the Updater/Restarter.
sudo nano /home/********/nextcloud/nextcloud_UPDATER.sh
chmod a+x /home/**********/nextcloud/nextcloud_UPDATER.sh
Setting permissions.
sudo chown -R www-data:www-data /mnt/md0/nextcloud/data/
sudo chmod -R 0750 /mnt/md0/nextcloud/data/
Starting up all docker containers and setting up the database.
sudo docker exec -it nextcloud-mariadb-server /bin/bash
mariadb -u root -p
***************
CREATE DATABASE nextcloud;
CREATE USER '*************'@'%' IDENTIFIED BY '*************';
GRANT ALL PRIVILEGES ON nextcloud.* TO '*************'@'%';
exit;
exit
Opening and setting up Nextcloud.
http://192.168.**.**:8080"
root
root
*************
*************
nextcloud
mariadb
Skipping recommended apps.
Checking the containers
sudo docker container ls -a
Cron should be used for internal updating of feeds and other things. Change it in the general administration settings. A separate container is used to run it, to keep everything self-contained.
Now configure everything to your liking.
DONE!
Now everything is set up. Files, the database, configs and other important things will be on a RAID and are much safer from drive failure than just on the system drive or a single drive. Firewall and Docker are configured for use within a local network and everything can be easily replicated, expanded or removed by using the compose files and removing individual directories for the no longer needed service. I hope I could help you get started or finding the next step for your setup!