Nextcloud deployment via Docker

It’s been a long time since posting but I thought I would document my deployment for others, and my future self, in case the same issues are discovered.

I recently decided to replace my Ubuntu server instance running Nextcloud installed via snap on DigitalOcean with a CentOS 7 (my personal server preference) instance deployed via Docker container. In my search for containers I found the guys over at LinuxServer.io have containers on Docker Hub. After joining their Discord community I was directed by one of the community team members the site blog post on deploying LetsEncrypt, MariaDB, and Nextcloud (with reverse proxy) all in one stroke. That blog post can be found here: Let’s Encrypt, Nginx & Reverse Proxy Starter Guide – 2019 Edition

Being a true noob at containers (I’ve taken classes but am still in the learning stage), I read the post and composed the docker compose file based on that article. That file is below. But, reader, if you have never setup Docker before, here are the steps I completed on CentOS 7 all before getting started on deploying the containers.

First, install and setup Docker:

1. Install pre-req

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

2. Add the repo

sudo yum-config-manager –add-repo https://download.docker.com/linux/centos/docker-ce.repo

3. Install the community edition

sudo yum install -y docker-ce docker-ce-cli containerd.io

4. Start and enable the service

sudo systemctl start docker && sudo systemctl enable docker

5. Add user to the ‘docker’ group

sudo usermod -aG docker $(whoami)

6. Test the config

docker run hello-world

Second, install Docker compose:

*Note: the latest version and instructions can be found on Docker’s site here

1. Download the latest version via curl

sudo curl -L “https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)” -o /usr/local/bin/docker-compose

2. Change executible permissions

sudo chmod +x /usr/local/bin/docker-compose

3. Check the version

docker-compose –version

Now, the next step for your cloud VPS, if you are deploying to the cloud, is to make sure your public domain’s DNS pointing to your VPS is setup correctly. DigitalOcean has great documentation on this process.

Now, after all is configured on your server, compose your Docker compose file and deploy. Below is a sample from my file. If you will note that I have volumes mounted. So that I had enough space for my files synchronization I also pay for block storage on DigitalOcean that is mounted to my VPS. Also, during the deployment, I had to generate an API token key on DigitalOcean. If you view your LetsEncrypt docker log during the deployment (see LinuxServer.io blog for reference) you will see it gripe about not having the proper credentials in the /config/dns-conf/digitalocean.ini file.

Docker compose

---
version: "3"
services:
  nextcloud:
    image: linuxserver/nextcloud
    container_name: nextcloud
    environment:
      - PUID=1001
      - PGID=1001
      - TZ=America/New_York
    volumes:
      - /mnt/myncvolume/nextcloud/config:/config
      - /mnt/myncvolume/nextcloud/data:/data
    depends_on:
      - mariadb
    restart: unless-stopped
  mariadb:
    image: linuxserver/mariadb
    container_name: mariadb
    environment:
      - PUID=1001
      - PGID=1001
      - MYSQL_ROOT_PASSWORD=myrootpassword
      - TZ=America/New_York
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=myusername
      - MYSQL_PASSWORD=mypassword
    volumes:
      - /mnt/myncvolume/mariadb/config:/config
    restart: unless-stopped
  letsencrypt:
    image: linuxserver/letsencrypt
    container_name: letsencrypt
    cap_add:
      - NET_ADMIN
    environment:
      - PUID=1001
      - PGID=1001
      - TZ=America/New_York
      - URL=myurl.org
      - SUBDOMAINS=wildcard
      - VALIDATION=dns
      - DNSPLUGIN=digitalocean
      - EMAIL=myemail@myemaildomain.com
    volumes:
      - /mnt/myncvolume/letsencrypt/config:/config
    ports:
      - 443:443
      - 80:80
    restart: unless-stopped

The above compose file was not my original file as I ran into scenarios where it didn’t seem to work in my original compose file during the initial Nextcloud configuration in the wizard, specifically at the section where you create an admin. The below screenshot is from when it finally worked. The problem I kept running into is that I was entering my actual name in the admin field and the root user in the bottom section thinking I needed to use the database root user to create the admin account. Using the docker compose sample above as a reference, you place the MYSQL_USER that the container creates for you in the bottom section. And all is well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s