How to build a Linux-powered smart home

Nextcloud via Docker... continued

At this point we could connect Nextcloud to a MariaDB container, and have both store their data in named volumes, which will provide portability. 

The resulting volumes will be available in the /var/lib/docker/volumes/ directory. We can also add boring names to our containers.

$ sudo docker run -d -p 8080:80 –name nextcloud -v nextcloud:/var/www/html nextcloud
$ sudo docker run -d -v db:/var/lib/mysql –name mydb -e MYSQL_ROOT_PASSWORD=secret1 mariadb

Getting these two containers to talk to each other is tricky, so we’ll refer you to the Docker Compose section in the documentation here, but we’ll return to this idea soon. 

Containers still continue to exist after they have been stopped. Multiple instantiations of the same one aren’t really a space issue, since the layers of the union filesystem are shared between them. 

But it’s nice to tidy up after yourself, so check your containers occasionally with docker ps and clear unwanted ones, such as our database above, with: 

$ sudo docker rm mydb

If you want to get rid of everything (danger, beware), you can do so with:

$ sudo docker rm $(sudo docker ps -aq)

You could at this point go back to the web installer and enter some administrative credentials, doggedly proceeding with the SQLite database, and reusing the first volume. 

But we’re going to borrow from the community and use the example Docker Compose setup, skimming over a few details which you should check in the documentation.

Running Docker this way uses four containers, one of which is a reverse proxy running Nginx, which can provide SSL encryption (which is essential if you make this installation available to the internet at large). 

Also existing in this setup is a Let’s Encrypt host to automatically update certificates. 

So if you’ve got a domain name setup, the whole thing will be seamless.

Grab the Compose recipe and environment from the Tutorials download, or fetch it from the nextcloud/docker repo on GitHub. 

Edit the docker-compose file, setting in particular the MySQL password, the virtual host (your domain name) and Let’s Encrypt variables.

Then follow the official documentation to install Docker Compose as this process may change. 

If something doesn’t work, you can peer into the logs of each container, for example:

$ sudo docker logs compose_proxy_1

One way or another, you’ll find your way back to the Nextcloud setup screen, and then all further configuration will be free of terminal commands. 

You just need to choose an admin password, use db for the database name (it uses Docker’s internal networking so doesn’t need a domain name) and wait a few moments for everything to be initialised. 

Your first step should be to create a new user, which you can do from the Users section in the drop-down menu in the top right. It’s better to keep the admin account for, well, admin. 

While you’re here, you can use your administrative privileges to see how apps are added to Nextcloud. Select Apps from the user menu in the top right, and you’ll find a categorised list of them. 

It’s good practice to keep your containers updated with the command:

$ docker-compose pull

from the directory with the docker-compose.yml file.