My previous attempt with self-hosting Nextcloud involved using VMs and a lot of manual installation and configurations, it works fine but: 1. its virtual disks were not configured in a way that’s easily expandable as data grows; 2. the entire setup is not very portable and convenient to manage and update. Using Docker effectively solves the issues.
Related articles:
- Self-host Nextcloud โ Part 1 โ Installation
- Self-host Nextcloud โ Part 2 โ Self-signed SSL Certificate
- Self-host Nextcloud โ Part 3 โ Performance
- Linux Administration: Install Docker on Ubuntu Server
- Docker Administration: MySQL Server
- Create Storage Pools and Virtual Disks via PowerShell
Components:
- The Docker host is a dedicated Hyper-V VM running Ubuntu Server in Windows Server 2022.
- Nextcloud Docker image.
- Ubuntu/MySQL Docker image.
- A storage pool consisting of 6 x 500GB 2.5” HDDs and a virtual disk in Parity mode with 2 disks set as redundant, bringing its total capacity to 1.35TB. This virtual disk will be mounted to Nextcloud’s
/var/www/html
path to store persistent data. - An 100GB virtual disk for MySQL persistent data (
/var/lib/mysql
). - [Optional] My custom Dockerfile.
- [Optional] My custom MySQL Dockerfile.
Configurations:
# Build Nextcloud image
docker build --file nextcloud.dockerfile --tag nextcloud:1.0 --progress plain --no-cache . 2>&1 | tee build.log
# Start the Nextcloud container.
# The drive for Nextcloud's persistent data is mounted to /mnt/nextcloud_data .
docker run -dit --name MY-NEXTCLOUD-CONTAINER --ip IP-ADDRESS --network NAME-OF-DOCKER-NETWORK --restart=unless-stopped --hostname=MY-NEXTCLOUD-CONTAINER-HOSTNAME -v /mnt/nextcloud_data:/var/www/html nextcloud:1.0
# Start a MySQL container for Nextcloud.
# The virtual disk for MySQL's persistent data is mounted to /mnt/nextcloud_db .
docker run -dit --name MY-NEXTCLOUD-DB-CONTAINER --ip IP-ADDRESS --network DOCKER-NETWORK --hostname=MY-NEXTCLOUD-DB-CONTAINER-HOSTNAME --restart=unless-stopped -v /mnt/nextcloud_db:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=MY-ROOT-PASSWORD ubuntu/mysql