Self-hosting Nextcloud with Docker: Self-hosting handbook

Self-hosting Nextcloud with Docker

Welcome to the fifth page of a handbook on self-hosting. Begin here. Read the previous page here. On this page, we’ll cover self-hosting Nextcloud with Docker (docker-compose, more specifically) on top of the stack we’ve built on previous pages.


Table of contents

  1. Self-hosting quickstart: Docker, domains, and DNS (look below!)
  2. A docker-compose tutorial
  3. Using docker-compose to add web apps
  4. Self-hosting administration
  5. Self-hosting Nextcloud with Docker

Topics covered on this page

  1. Why is self-hosting Nextcloud a good idea?
  2. What to add to your docker-compose.yml file
  3. Create your admin user and setup your database

Hi there! This is a blog post from the people behind SSD Nodes.

We’re the first honest-value VPS provider. Instead of inflating costs, our engineers developed a lean infrastructure that lets us offer up to 10x more RAM per dollar than the competition.

Ready to learn more about what you get from an honest VPS provider? Here’s a hint: Our 24GB RAM + KVM VPS is only $9.99/mo.

Learn more about us ⚡

Why is self-hosting Nextcloud a good idea?

My journey into self-hosting began with a simple problem: I wanted to be able to synchronize files between my various machines, a la Dropbox, but I didn’t want to pay yet another monthly SaaS subscription. My VPS-as-VPN experiment wasn’t going well, and so I decided to give my relatively unused VPS some new life.

That’s the great thing about self-hosting with a VPS—you can always pivot how you’re using it, or add something new on top of what you’re already doing (as long as you don’t run out of resources!). That’s a great way to get a return on your VPS investment.

On top of that, self-hosting Nextcloud offers many other benefits. I like the ability to completely control my data instead of handing it off to Dropbox or another cloud drive service like Google One (once Google Drive) or Microsoft’s OneDrive.

I don’t use many of Nextcloud’s features beyond simple file synchronization, but you can also migrate away entirely from Google if you’d like, as it offers everything from contacts, chats, calendars, photo organization, bookmarks, TODOs, and more.

What to add to your docker-compose.yml file

To delpoy a self-hosted Nextcloud server, you need to add three new services to your existing docker-compose.yml file. If you landed here first and you don’t have one, be sure to start at the beginning of this handbook for more details.

Here are the three services in full:

  nextcloud:
    image: nextcloud:apache
    container_name: nextcloud
    restart: unless-stopped
    environment:
      - VIRTUAL_HOST=SUBDOMAIN.DOMAIN.TLD
      - LETSENCRYPT_HOST=SUBDOMAIN.DOMAIN.TLD
      - [email protected]
      - PGID=999
      - PUID=1000
    volumes:
      - ./nextcloud:/var/www/html
    ports:
      - "666:80"
    networks:
      - proxy-tier
      - default
    depends_on:
      - "db"

  db:
    image: mariadb
    container_name: db
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: PASSWORD
      MYSQL_PASSWORD: PASSWORD
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
    volumes:
      - ./db:/var/lib/mysql
    ports:
      - "3306:3306"

As with previous examples, begin by replacing SUBDOMAIN.DOMAIN.TLD and [email protected] with your own domain details and email. You might also want to change the container_name field, depending on your needs. I also highly recommend changing the MYSQL_ROOT_PASSWORD and MYSQL_PASSWORD fields as well.

Once you’ve added these items, you should be able to deploy Nextcloud via a docker-compose up -d. After pulling images and deploying new containers, your Nextcloud server should be up and running on the subdomain of your choice! Hop over there on your browser of choice to see the admin account creation screen.

Create your admin user and setup your database

First, choose a username and (secure) password for your administrator account.

Then click the Storage & database link to see options for configuring a database, and then click on the MySQL/MariaDB button. You’ll need to enter a few pieces of information based on your docker-compose.yml file. If you left the default environment variables in place, you’d use the following:

nextcloud
PASSWORD
nextcloud
db

Hit the button to move forward, and after a few moments, you’ll be dropped into the Nextcloud web interface! You can now configure Nextcloud’s desktop/mobile apps to synchronize files to your self-hosted Dropbox alternative. Pretty sweet, no?


Bookmark this guide and follow us on Twitter or Mastodon to get updates. Or, you can subscribe to the weekly Serverwise newsletter, where I’ll let you know as soon as this guide expands.

The 10X cloud for developers who demand performance.

We've pioneered next-generation cloud hosting with NVMe disk technology: 10X performance at 1/5 the price of slower servers from DigitalOcean, Linode, and Vultr. Deploy faster and scale at a fraction of the cost.

Go 10X now →