Personal cloud with Raspberry Pi and NextCloud on Docker

Last Updated on

This guide will provide us a very simple way to have a personal cloud with Raspberry Pi. We’ll use a Raspberry Pi 3 model B+, with an external USB drive that will store all our data. Our USB disk will be formatted in this procedure in order to assure that it will work. So be aware to use a free USB disk in order to avoid lose of data at format time.

From software side, we’ll use Docker to have the enhancements obtained from container and NextCloud.

What We Need

Raspberry PI 3 Model B+ image

As usual, I suggest adding from now to your favourite ecommerce shopping chart all needed hardware, so that at the end you will be able to evaluate overall costs and decide if continuing with the project or removing them from shopping chart. So, hardware will be only:

Step By Step Guide

Prepare OS environment

Our private cloud will be installed on official lite operating system. Use install Raspberry PI OS Lite guide to accomplish this task. Once done, remember to update from terminal:

sudo apt update -y && sudo apt upgrade -y

We are now ready to install Docker in Raspberry Pi.

Enable USB Mount at boot

We’ll use an USB drive to write data. So, we need to be sure that at every boot the USB Disk will be ready, without struggling on mounting it from terminal. For this purpose, I’ll use USBmount. Type on terminal:

sudo apt install usbmount

To be sure it will works, we need to change the line PrivateMounts=yes to PrivateMounts=no in “/lib/systemd/system/systemd-udevd.service”. Type

sudo nano /lib/systemd/system/systemd-udevd.service

and change the matching line.

Reboot the Raspberry PI. Now, the simple command “mount” should list the following line within the other mounted devices:

/dev/sda on /media/usb0 type vfat (rw,nodev,noexec,noatime,nodiratime,sync,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)

If we want to make USB drive writable from users (not only from root), we need to edit usbmount.conf:

sudo nano /etc/usbmount/usbmount.conf

identify “FS_MOUNTOPTIONS” and edit it as follow:

FS_MOUNTOPTIONS="-fstype=vfat,umask=0000"

where:

  • vfat is the filesystem
  • umask=0000 is the permission of the file and folder. 0000 means rwx-rwx-rwx

Now reboot.

Prepare Your USB Device

I experienced some issues formatting my USB disk in FAT32. The only way I found to have a working installation was to format in ext4 the flash disk. Be aware: this operation will erase ALL your data in your USB disk.

According with an askUbuntu guide (https://askubuntu.com/questions/22381/how-to-format-a-usb-flash-drive), identify the USB drive among all storage partitions and volumes on your computer use:

lsblk

You can also use:

df -H

Suppose it may be /dev/sda. Unmount it with:

sudo umount /dev/sda

To format drive with the ext4 file system format:

sudo mkfs.ext4 /dev/sda

Reboot to have it mounted and ready to be used for our docker volumes.

NOTE: in next section I’ll assume that your USB Disk is the only disk plugged on RPI. This should assure that at the boot it will be mounted on “/media/usb0”.

Install Nextcloud Container

It’s time to use Docker. As usual, it allows us to install and prepare the container with 1 row (copy and paste the entire following command):

docker run -d -p 8080:80 --name nextcloud --restart unless-stopped \
    -v /media/usb0/nextcloud:/var/www/html \
    -v /media/usb0/apps:/var/www/html/custom_apps \
    -v /media/usb0/config:/var/www/html/config \
    -v /media/usb0/data:/var/www/html/data \
    -v /media/usb0/theme:/var/www/html/themes \
     nextcloud

this simple command will map all main volumes on your USB key and initialize Nextcloud container. Be patient, because slow USB disks will require a while to prepare the container. You will be able to monitor installation process by typing:

docker logs nextcloud

or simple monitoring increasing USB disk space used from Nextcloud (on /media/usb0):

watch df -H

at the end of process it should have been used about 370MB of space.

Login nextcloud and last settings

Once the initialization have been completed, open with your browser the address http://<<YOUR_RPI_IP_ADDRESS>>:8080. You will see the following homepage (in your language, depending on your browser settings):

nextcloud setup page

If you want to use an external database, you have to set it in database section (link below the password field). If you want to use the built-in SQLlite DB, just insert username and password which you want to use for your cloud page and click on finish configuration to access (again, after a while for database initialization and recommended apps installation, if selected) the Nextcloud presentation pages and, after a few next, to Nextcloud home page:

nextcloud home page

Enjoy!

Check hardware prices with following links:

Amazon raspberry pi boards box
Amazon Micro SD box