5$ Personal Cloud: How to, using Nextcloud, and Docker-Compose

Official work as begun on a Nextcloud Docker container.
I really like Docker for it's ability to compartmentalize applications and services at your own whim.

I personally very much like having each service separated by Docker. One advantage of this is you can make changes to the web server for one application without having to briefly take down all of the hosted applications.

Obtaining a VPS

In order to use Nextcloud, it is necessary to host the service somewhere. While this can be done at home, the best experience is when using a Virtual Private Server.

For my example I am using a DigitalOcean droplet using Debian 9. Once signed up, choose the 5$ plan and create a new droplet.

Configuring your Droplet

You will first login as root, this is dangerous, we will start by creating our own user.

Add a non-root user

One of the first steps one should take when spinning up a VPS is to create, and log in as, a non-root user.

Replace user in these examples with your desired username.

root@hostname:/# adduser user

Before we can log in as our new user, you should add your user to sudo.

root@hostname:/# usermod -aG sudo user

Finally, sign into the newly created user

root@hostname:/# su - user

We will be using this user account for the rest of the tutorial.

Writing a Docker Compose file

The Nextcloud Github page offers several options for using the Nextcloud development container. I opted to use the fpm version with nginx proxy. This automatically configures LetEncrypt on the nginx proxy.

I recommend using wget or something similar to download the docker-compose file directly. I have been bitten by formatting differences using copy/paste.

Spinning up the Composition

The docker-compose.yml will create and spin up docker containers, networks,
and volumes based on the configuration we write inside.

We can spin up the composition using docker-compose up. The -d flag will run it in detached mode and free up our shell after starting the composition.

user@hostname:~$ sudo docker-compose up -d

Essential Commands

Shows list of running containers

user@hostname:~$ sudo docker container list

Stop the composition

user@hostname:~$ sudo docker-compose stop

Starts the containers without recreating them

user@hostname:~$ sudo docker-compose up -d --no-recreate

Where Your Files Go

The next sane thing one should do is configure their own backup solution.

When uploading files to Nextcloud they will be stored in their standard location under the Nextcloud root directory /var/lib/docker/volumes/fpm_nextcloud/_data on the host machine.
If you want to store your files in location you specify you can add the following to the docker-compose.yml:

volumes:
  - /path/you/want:/var/html/

If you look inside /var/lib/docker/volumes/ you will see several directories. The directory namedfpm_nextcloud refers to the name of the volume created by the container holding the nginx webserver for Nextcloud.

The Nextcloud instance created under fpm-nextcloud has Nextcloud configured to the default /var/html/www directory of the container.