Home Lab Guide: Nextcloud

Deploy your own private file hosting from scratch!

Home Lab Guide: Nextcloud
Photo by Taylor Vick / Unsplash

Over this past summer I had the opportunity to intern in Boston at The MITRE Corporation. Through my tasking at the company I was able to learn DevOps tooling such as Kubernetes and Docker. This ignited a passion in me to create my own testbed and start experimenting with the different technologies I was learning about. One of the cooler things I deployed was a private google drive alternative called Nextcloud which was selfhosted on my domain. In this post I'll be showing you how to deploy your own instance of the service from scratch.

Setting up Your Environment

The rest of the guide will assume you're using a unix based operating system (i.e. WSL2, Ubuntu, MacOS, etc.)

First things first we need to install Docker Engine:

sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Now we need to create the file structure for our home lab. This will help us greatly down the line when we're trying to add more services to our stack by keeping it clean and organized.

cd ~
mkdir homelab
cd homelab
mkdir appdata
touch docker-compose.yml

Building the Stack

Finally it's time to write our compose file. Copy the following into docker-compose.yml:

version: "3.9"

x-environment: &default-environment
    PUID: 1000
    PGID: 1000
    TZ: America/New_York #replace with your timezone

        image: lscr.io/linuxserver/nextcloud:latest
        container_name: nextcloud
            <<: *default-environment
        - ./appdata/nextcloud:/config #holds config files for the container
        - /location/for/storage:/data #where you keep the stored data
        - 443:443
        restart: unless-stopped
The x-environment section is a handy trick that becomes useful when adding multiple services into a compose file that have similar config settings. We'll see this in future blog posts where we add more services.

Now run the next line to deploy:

sudo docker compose up

Accessing your Nextcloud Instance

Navigate to https://localhost:443 in your browser:

Create the admin account and click install. Congratulations, you have your own private google drive!

In the next blog post I'll show you how to securely connect to the service on your own domain using Cloudflare Zero Trust and Cloudflare Tunnel for free.