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

What's the BEST DEAL in cloud hosting?

Develop at hyperspeed with a Performance VPS from SSD Nodes. We DOUBLED the amount of blazing-fast NVMe storage on our most popular plan and beefed up the CPU offering on these plans. There's nothing else like it on the market, at least not at these prices.

Score a 16GB Performance VPS with 160GB of NVMe storage for just $99/year for a limited time!

Get limited-time deals!⚡

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.

[cta]